UIActionSheet无法识别的选择器错误

1 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");


    }
}
Run Code Online (Sandbox Code Playgroud)

这是抛出的错误:

-[__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'
Run Code Online (Sandbox Code Playgroud)

有趣的是,它不是作为更大代码的一部分运行,而是在独立的基础上运行良好.

Ste*_*ton 7

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

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