Reputation: 1113
In my app, I have a second view controller for another screen. This view controller has a close button that dimisses the view controller. On pressing this close button, the app crashes. It crashes with the following error:
*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
This is the method I use to close the view controller, in the second view controller's .m
- (IBAction)done {
[self dismissViewControllerAnimated:YES completion:nil];
//[self dismissModalViewControllerAnimated:YES];
}
The crash occurs at [self dismissViewControllerAnimated:YES completion:nil];
The second view controller is presented using this method in my main view controller:
-(IBAction)switchViews {
[self presentViewController:secondView animated:YES completion:nil];
//[self presentModalViewController:secondView animated:YES];
}
Code related to rotation in main view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskPortrait;
}
I haven't been able to resolve this issue. I've looked up that error and tried various solutions, but nothing has worked. Why is this crash happening? What am I doing wrong?
If you need more information, please let me know.
Upvotes: 0
Views: 621
Reputation: 31143
You are returning the wrong thing. The value it expects is UIInterfaceOrientationPortrait
, but you're returning UIInterfaceOrientationMaskPortrait
. Note the Mask part.
Upvotes: 1