我得到的错误无法识别的选择发送到实例,iPhone错误
“012-02-10 13:54:52.570的HelloWorld [14275:10103] - [HelloWorldViewController buttonPressed]:无法识别的选择发送到实例0x6cc0c50 2012-02-10 13:54:52.572的HelloWorld [14275:10103] *终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因: ' - [HelloWorldViewController buttonPressed]:无法识别的选择发送到实例0x6cc0c50'”。
这是有问题的文本:
-(void)buttonPressed:(id)sender {
UIButton *button = (UIButton*)sender;
NSString *text = [button titleForState:UIControlStateNormal];
NSLog(@"%@",text);
}
我知道这是因为,如果我更改代码这样:
-(void)buttonPressed {
NSLog(@"Button Pressed");
}
然后它工作正常。
但是我需要发送消息的组件中的文本。组件不会通过IB拖放。它们被分配,初始化并放置在loadView方法中。对于我的每个按钮,我都添加了buttonPressed作为动作侦听器。
您能否显示添加动作侦听器的代码? – 2012-02-10 14:10:57