iOS: How to use photos Framework (iOS 8.0)? [closed] - ios

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How to use photos Framework (iOS 8.0)? I wanna get one result that can show one by one image in the UICollectionView.

If you want a fetchResult with all images, you can solve it like this:
// Property in your UICollectionViewController.h file
#property (strong, nonatomic) PHFetchResult *allPhotosFetchResult;
// In your awakeFromNib or where you refresh your Data
PHFetchOptions *allPhotosOptions = [PHFetchOptions new];
allPhotosOptions.sortDescriptors = #[[NSSortDescriptor sortDescriptorWithKey:#"creationDate" ascending:NO]];
self.allPhotosFetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosOptions];
In your collectionView:cellForItemAtIndexPath: method you can access the asset with
self.allPhotosFetchResult[indexPath.row];
To get the number of rows in collectionView:numberOfItemsInSection:
self.allPhotosFetchResult.count

Related

iOS UIViewControler singleton and how to use helper class? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I follow the online way to write singleton, each into SecondViewController, address of the print is the same , but why UISwitch interface is initialized ? I was into the original UIViewController? someone was also suggested to write helper class. Everthing is beginning, it is not very clear, Is there any Demo or explain the basic principles?How to write the code depend on second image?
enter image description here
enter image description here
Try this code
static SecondViewController *sharedVCInstance = nil;
+ (SecondViewController *)sharedInstance
{
static dispatch_once_t onceToken = 0;
dispatch_once (&onceToken, ^{
if(sharedVCInstance == nil)
sharedVCInstance = [[SecondViewController alloc] init];
});
return sharedVCInstance;
}

What is the best way to display pdf in objective-c? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I need to display pdf documents within my iPad app, I've seen people suggesting loading it within a webview.
I want to know if this is the best\recommended way to display a pdf?
Using a QuickLook.framework you can easly load pdf and disply i just add following easy step for load pdf using QuickLook.framework
Add QuickLook.framework and import in to your class and set it's DataSource in to .h class <QLPreviewControllerDataSource>
Use following method:
-(NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:self.pdfFilePath]; // here is self.pdfFilePath its a path of you pdf
}
and for load set Button Action:
-(IBAction)LoadPdf
{
QLPreviewController* preview = [[[QLPreviewController alloc] init] autorelease];
preview.dataSource = self;
[self presentModalViewController:preview animated:YES];
}
Two easiest way to that
UIWebView
QLPreviewController

Empty NSMutableArray after adding elements [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Here's my project: https://github.com/a8b/musicManager/tree/master/musicManager
I have issue with addSongToLibrary method in MusicCollection.m - it doesn't add songs with [library addSong:song]
To simplify your code for clarity, it's doing this:
-(void) addSongToLibrary:(Song *)song {
for (Song *song in library.songs) {
NSLog(#"%#", song);
}
[library addSong:song];
}
}
You are declaring a variable with the same name as a method parameter, so it is hiding the value passed in.
Well you commented out the following code
/*-(instancetype) init {
self = [super init];
if (self) {
library.songs = [NSMutableArray array];
[library addSong:[Song new]];
}
return self;
}*/
so library is never instaniated, either you uncommented it , or in viewDidLoad you need to add library.songs = [NSMutableArray array]; otherwise it will be nil.

Objective C NSArray [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to append data to NSArray and than get count of data in NArray and retrieve data at specific index.
I am adding data as follows:
NSArray *oneInfo = #[
#{#"trackTime" :theTrack[#"seconds"],
#"trackPrice":theTrack[#"price" ],
#"trackWait" :theTrack[#"wait" ]
}
];
Your array is an array literal which means it is immutable. In order to make an array that you can change, do this:
NSArray *oneInfo = #[#{#"trackTime":theTrack[#"seconds"],#"trackPrice":theTrack[#"price"],#"trackWait":theTrack[#"wait"]}];
NSMutableArray* somethingICanChange = [oneInfo mutableCopy];
[somethingICanChange addObject: moreData];
Note that, if you are not using ARC (why not?), somethingICanChange is an array that you own and needs to be released or autoreleased when you are done with it.
You can not append NSArray you have to create NSMutableArray for appending and other changes your need.
oneInfo = [oneInfo arrayByAddingObject: something];

How to save the state of a iPhone Switch and print it out? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a switch on my ViewController, and whenever I press the save button, I want to use NSLog to print out if the switch is On/Off.
My question is, What data type saves the state of a switch? And how would I print out that variable with the state?
EDIT:
If it was a DatePicker, it would be
#property (nonatomic, strong) NSDate *pickerDate;
I need the Switch version of this. NSSwitch doesn't seem to work.
UISwitch has a BOOL property called "on". Say your switch is called "theSwitch"
if(theSwitch.on) {
NSLog(#"on")
}
else {
NSLog(#"off")
}
#property (nonatomic, strong) UISwitch *aSwitch;
if(aSwitch == nil)
NSLog("Oops, switch is nil, you cannot save its state");
NSLog(#"switch is:%#", aSwitch.on? #"on", #"off");

Resources