无法识别的选择,我不能相信我跌倒在这么简单的东西:按下按钮
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Tap me" forState:UIControlStateNormal];
[button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(50, 50, 120, 60);
[self.view addSubview:button];
}
return self;
}
-(void)test {
NSLog(@"Test");
}
它,当我按下按钮,与unrecognized selector sent to instance
错误崩溃。
有人知道我会在这里做错吗?
编辑 - 错误信息:
-[__NSCFString test]: unrecognized selector sent to instance 0x29ee30
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString test]: unrecognized selector sent to instance 0x29ee30'
编辑 - 它是如何呈现(ARC):
DemoViewController *demoVC = [[DemoViewController alloc] init];
[self.window addSubview:demoVC.view];
[self.window makeKeyAndVisible];
请问您能否发布确切的错误代码? – Pfitz
你在.h文件中声明了'test'吗? – WendiKidd
你确定你收到“无法识别的选择器发送到实例”,而不是另一个异常? –