【发布时间】:2012-02-10 14:07:36
【问题描述】:
我得到了错误
“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 作为动作监听器。
【问题讨论】:
-
你能显示添加动作监听器的代码吗?
标签: iphone ios uibutton unrecognized-selector method-invocation