我正在尝试遵循此示例中的代码:iOS 6: How do I restrict some views to portrait and allow others to rotate?
我创建了一个名为 customNavigationController 的 UINavigationController 子类:
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
然后在我的应用中,我尝试在 viewWillAppear 中设置 landscapeOK 属性:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
[(CustomNavigationController*)[self navigationController] setLandscapeOK:NO];
}
当我运行 [(CustomNavigationController*)[self navigationController] setLandscapeOK:NO];
我得到错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setLandscapeOK:]: unrecognized selector sent to instance 0x10091ee00'
我做错了什么?
最佳答案
您必须在 Storyboard中的导航 Controller 的身份检查器中将自定义类设置为 CustomNavigationController
。
关于iOS NSInvalidArgumentException : Unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32340554/