我尝试编译并运行这个简单的代码,但它正在抛出错误
- (void)doSomething
{
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure?"
delegate:self
cancelButtonTitle:@"No Way"
destructiveButtonTitle:@"Yes, I'm Sure!"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
NSLog(@"ok");
}
}
这是抛出的错误:
-[__NSCFData actionSheet:clickedButtonAtIndex:]: unrecognized selector sent to instance 0x6d6df80
2010-10-25 16:07:36.120 iota[31172:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData actionSheet:clickedButtonAtIndex:]: unrecognized selector sent to instance 0x6d6df80'
有趣的是,它不是作为更大代码的一部分运行,而是独立运行。
答案 0 :(得分:7)
它发送actionSheet:clickedButtonAtIndex:
消息的实例似乎认为它的类型为NSData
(CFData
)。这告诉我,在按下按钮之前,self
的实例可能已被解除分配。
添加委托不会保留委托,因此只要UIActionSheet
可见,您就需要保留它。