我创建了一个按钮并为其添加了一个操作,但一旦它被调用,我就得到了这个错误:

-[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(@"---");
}

推荐答案

看起来您没有正确地管理视图控制器的内存,并且它在某个点被释放,这导致numberButtonClicked:方法被发送到另一个对象,该对象现在正在占用视图控制器以前占用的内存...

确保正确固定/释放视图控制器.

Objective-c相关问答推荐

如何判断 iPhone 现在在哪个位置(横向或纵向)?

Objective C 中的多个委托

等到多个网络请求都执行完毕 - 包括它们的完成块

如何用零填充左侧的整数?

Objective-C,如何获取 UTC 时区的当前日期?

从 float 或 double 实例化 NSDecimalNumber 的正确方法

如何在for (id item in items)objective-c 循环中获取数组索引?

performSelector 的返回值:

将长格式的 NSString 拆分为多行

ios 13 - 带有 UISearchBar _searchField 的自定义 SearchBar 不起作用

混合 Objective-C 和 C++

UIScreen MainScreen Bounds 返回错误的大小

如何与 UITableView 一起滚动标题?

NSUInteger 不应该在格式字符串中使用吗?

arc4random 和 arc4random_uniform 有什么区别?

如何从 CGPoint 和 CGSize 创建 CGRect?

如何用 Java 开发 iPhone 应用程序?

判断是否已实现可选协议方法

iOS ScrollView 需要约束 y 位置或高度

UITableViewCell 选中行的文字 colored颜色 变化