I work on iPad 4 with iOS 6.0.
I have a ViewController (MyPickerController) with the following init:
- (id)init
{
self = [super init];
if (self) {
_picker = [[UIImagePickerController alloc] init];
_picker.delegate = self;
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.view addSubview:_picker.view];
}
return self;
}
I implement the following UIPickerControllerDelegate method to dimiss MyPickerController:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Well, I have another view controller showed modally in FormSheetStyle
and when I tap on a button I want to show MyPickerController
with the following code:
MyPickerController * pickerVC = [[MyPickerController alloc] init];
[self presentViewController:pickerVC animated:YES completion:nil];
In my AppDelegate i Have the following totation method:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return (NSUInteger)[application supportedInterfaceOrientationsForWindow:window] | (1<<UIInterfaceOrientationPortrait);
}
When I tap on cancel button of UIIMagePicker
into MyPickerController
, the application crashes with the following error:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!
Reading related questions on stackoverflow, I create also the follwing UIImagePickerController category:
@implementation UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
@end
Thank you!
Try doing this..
If your view controller is inside a UINavigationController, you should use this category for the navigationcontroller:
@implementation UINavigationController (autorotate)
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationMaskPortrait;
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With