-(void) openPhotoLib:(id)sender {
[self dismissModalViewControllerAnimated:YES];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:YES];
NSLog(@"openPhotoLib called");
}
Nothing happens except for the NSLog, even though my view controller is a subclass of UINavigationController and UIImagePickerDelegate. Does anyone have any insight or experience with UIImagePickerController?
I should note that I’m primarily using an iPhone for testing.
SOLUTION: Make a new class that subclasses ONLY UINavigationBarDelegate and UIImagePickerDelegate. In that classes’s viewDidAppear, put the code to modally present the imagePicker. Create an instance of this class inside the method (inside another class, import the .h file and all) and the modally present that class.
^ I take it back. The modal animations was the real problem. Trying to use another class instance for this messes up the method implementations of UIImagePicker.
The problem is due to
dismissModalViewControllerAnimatedandpresentModalViewControllerbeing called one after the other.The dismiss action takes some time as it has to animate the view being dismissed. During the animation, it is still the top Modal View. So, you cant present another model view during that time. If you try then the call fails and does nothing.
To fix, use
[self dismissModalViewControllerAnimated:NO];i.e no animation.If you still want animation then follow one of these solutions:
Problem opening new ViewController after UIImagePickerController
Correct way of showing consecutive modalViews