ios - 另一个“NSInvalidArgumentException:无法识别的选择器发送到实例”帖子

标签 ios cocoa-touch

整周都在添加敲击手势识别器,但我去做了,就像Ive做了所有其他事情一样,我的应用程序崩溃了。我一定想念一些东西,但是对于我的一生,我找不到它。我已经阅读了十多篇有关此错误的SO文章,但没有任何帮助。

这段代码:

@interface wwfpViewController ()
@property (nonatomic, strong) UIView * firstScreen;
@end

@implementation wwfpViewController

@synthesize firstScreen;

- (void)viewDidLoad {
    [super viewDidLoad];
    firstScreen=[[UIView alloc] initWithFrame:self.view.frame];
    [firstScreen setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:firstScreen];

    UITapGestureRecognizer * tap=[[UITapGestureRecognizer alloc] initWithTarget:firstScreen action:@selector(onTap:)];
    [tap setNumberOfTapsRequired:1];
    [firstScreen addGestureRecognizer:tap];
}

- (void) onTap:(UIGestureRecognizer*) recogniser {
    NSLog(@"tap: %@",recogniser);
}

@end

产生此错误:
2013-08-01 12:50:11.027 tyrionSwipe[27336:11303] -[UIView onTap:]: unrecognized selector sent to instance 0xe52c4a0
2013-08-01 12:50:11.029 tyrionSwipe[27336:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView onTap:]: unrecognized selector sent to instance 0xe52c4a0'
*** First throw call stack:
(0x1c91012 0x10cee7e 0x1d1c4bd 0x1c80bbc 0x1c8094e 0x2dd85a 0x2dc99b 0x2de0df 0x2e0d2d 0x2e0cac 0x2d8a28 0x45972 0x45e53 0x23d4a 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1beb7e3 0x1beb668 0x12ffc 0x295d 0x2885 0x1)
libc++abi.dylib: terminate called throwing an exception

有人可以帮忙吗?

编辑:我打错了!哎呀。即使没有错字,我仍然会收到此错误。

最佳答案

这只是一个错字
将方法onTap重命名为tap或将选择器从tap:重命名为onTap:

看看目标,我很确定你的意思是自我,因为firstScreen只是一个UIView

关于ios - 另一个“NSInvalidArgumentException:无法识别的选择器发送到实例”帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17993295/

相关文章:

objective-c - NSPrivateQueueConcurrencyType 未正确保存

ios - NSPredicate/TableView 只显示一项,为什么?

ios - 在使用自定义 UITableViewCell 时解决没有自定义 init 方法的问题

ios - Facebook iOS SDK FBSDKAccessToken.currentAccessToken() 即使在登录时也为零?

iphone - 关闭 UIImagePicker 后获取视频长度?

ios - Material 组件选项卡 Swift 中的项目大小

ios - 为什么CALayer的动态@property可以调用setter方法?

ios - Swft3 (RxSwift, RxCocoa) - 使用响应式(Reactive)编程的 TableView 展开和折叠概念

ios - 如何从地址簿中检索 'self'

objective-c - 相对日期格式,过去日期的输出?