objective-c - Objective-C 中的 "unrecognized selecto

我创建了一个按钮并为它添加了一个 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/

相关文章:

objective-c - Xcode 构建失败 "Undefined symbols for ar

objective-c - NSLog iPhone中Objective-C的方法名

objective-c - 如何将字符串转换为 double ,反之亦然?

iphone - @synthesize 到底是做什么的?

ios - 调整 UITableView 的大小以适应内容

ios - 如何使用 AVAudioRecorder 在 iPhone 上录制音频?

ios - iOS 上 Objective-C 中的类型

objective-c - 每个核心数据关系都必须有一个逆关系吗?

ios - 为什么 NSUserDefaults 无法在 iOS 中保存 NSMutableDict

iphone - 在 UIViewController 上显示 clearColor UIViewC