I am trying to follow the code in this example: iOS 6: How do I restrict some views to portrait and allow others to rotate?
I created a subclass of UINavigationController called customNavigationController:
customNavigationController.m
@implementation CustomNavigationController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.landscapeOK) {
NSLog(@"all orientation ok");
return UIInterfaceOrientationMaskAllButUpsideDown;
}
NSLog(@"only portrait orientation");
return UIInterfaceOrientationMaskPortrait;
}
@end
CustomNavigationController.h
@interface CustomNavigationController : UINavigationController
@property (nonatomic) BOOL landscapeOK;
@end
Then in my app, I try setting the landscapeOK property in viewWillAppear:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
[(CustomNavigationController*)[self navigationController] setLandscapeOK:NO];
}
When I run [(CustomNavigationController*)[self navigationController] setLandscapeOK:NO];
I get the error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setLandscapeOK:]: unrecognized selector sent to instance 0x10091ee00'
What am I doing wrong?