iOS NSInvalidArgumentException : Unrecognized selector sent to instance

标签 ios objective-c

我正在尝试遵循此示例中的代码: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/

相关文章:

ios - Stripe 和 Parse SDK 用于存储信用卡

objective-c - 圆形 CALayer 周围的边框较深

iphone - 有没有获取全局当前时间的API

ios - 在 applicationWillEnterForeground 触发时更改 UIView

iOS - 与多个应用程序目标共享 Today Extension?

ios - 发布 Facebook Open Graph 故事时如何选择一对多?

objective-c - 在 Mac 应用程序中嵌入可执行文件

ios - 如何避免将从相机胶卷中选取的图像保存到相机胶卷? [iOS]

ios - 如何使用 bundle 中的数据移动 sqlite3 数据库

ios - 带阴影的线圆