UIActionSheet无法识别的选择器错误

时间:2010-10-25 10:50:06

标签: iphone iphone-sdk-3.0

我尝试编译并运行这个简单的代码,但它正在抛出错误

- (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'

有趣的是,它不是作为更大代码的一部分运行,而是独立运行。

1 个答案:

答案 0 :(得分:7)

它发送actionSheet:clickedButtonAtIndex:消息的实例似乎认为它的类型为NSDataCFData)。这告诉我,在按下按钮之前,self的实例可能已被解除分配。

添加委托不会保留委托,因此只要UIActionSheet可见,您就需要保留它。