我创建了一个按钮并为它添加了一个 Action ,但是一旦它被调用,我就得到了这个错误:
-[NSCFDictionary numberButtonClick:]: unrecognized selector sent to instance
0x3d03ac0 2010-03-16 22:23:58.811
Money[8056:207] *** Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:'*** -[NSCFDictionary numberButtonClick:]: unrecognized selector sent to instance 0x3d03ac0'
这是我的代码:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
UIButton *numberButton = [UIButton buttonWithType:UIButtonTypeCustom];
numberButton.frame = CGRectMake(10, 435, 46, 38);
[numberButton setImage:[UIImage imageNamed:@"one.png"] forState:UIControlStateNormal];
[numberButton addTarget:self action:@selector(numberButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: numberButton];
}
return self;
}
-(IBAction)numberButtonClick:(id)sender{
NSLog(@"---");
}
最佳答案
看起来您没有正确管理 View Controller 的内存并且它在某个时候被释放 - 这导致 numberButtonClicked:
方法被发送到另一个正在占用内存的对象 View Controller 之前占用...
确保您正确地保留/释放您的 View Controller 。
关于objective-c - Objective-C 中的 "unrecognized selector sent to instance"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2455161/