在我的应用程序中,我已经有一个按钮,这是一个实例变量已在.h文件中声明。 现在分配是一个分配的目标,并实际上按下按钮后,应用程序崩溃给我在调试器输出如下:UIButton调用选择器崩溃的应用程序
-[__NSCFString handleActionSheet:]: unrecognized selector sent to instance 0x9090330
2012-05-04 17:51:02.646 financeAppV2[2595:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString handleActionSheet:]: unrecognized selector sent to instance 0x9090330'
*** First throw call stack:
(0x13d1022 0x1562cd6 0x13d2cbd 0x1337ed0 0x1337cb2 0x13d2e99 0x1e14e 0x1e0e6 0xc4ade 0xc4fa7 0xc3d8a 0x2dfa1a 0x13a599e 0x133c640 0x13084c6 0x1307d84 0x1307c9b 0x12ba7d8 0x12ba88a 0x1b626 0x29dd 0x2945)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
我的代码看起来像以下:
saveButton=[UIButton buttonWithType:UIButtonTypeCustom];
[saveButton setBackgroundImage:[UIImage imageNamed:@"intervalbutton"] forState:UIControlStateNormal];
[saveButton setBackgroundImage:[UIImage imageNamed:@"intervalbuttonpressed"] forState:UIControlStateHighlighted];
saveButton.alpha=.8;
saveButton.frame= frame;
UILabel* label=[[UILabel alloc]initWithFrame:CGRectMake(0, 2, saveButton.frame.size.width, 21)];
[saveButton addSubview:label];
[saveButton addTarget:self action:@selector(handleActionSheet:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:saveButton];
-(void)handleActionSheet:(id)sender{
NSLog(@"working");
}
任何想法为什么应用程序可能会崩溃?
这样还是会发生,如果你注释'[saveButton addSubview:label];'? – Costique
是的。事实上,我甚至得到一个陌生人的错误: - [_ UITableViewSeparatorView handleActionSheet:]:无法识别的选择器发送到实例0x6a89a30 2012-05-04 18:12:52.485 financeAppV2 [2997:f803] ***由于未捕获的异常终止应用程序'NSInvalidArgumentException' 的,理由是: ' - [_ UITableViewSeparatorView handleActionSheet:]:无法识别的选择发送到实例0x6a89a30' ***第一掷调用堆栈: (0x13d1022 0x1562cd6 0x13d2cbd 0x1337ed0 0x1337cb2 0x13d2e99 0x1e14e 0x1e0e6 0xc4ade 0xc4fa7 0xc3d8a 0x2dfa1a 0x13a599e 0x133c640 0x13084c6 0x1307d84 0x1307c9b 0x12ba7d8 0x12ba88a 0x1 ... – iJatrat