views:

22

answers:

1

I tried compiling and running this simple code but it's throwing error

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


    }
}

This is the error thrown:

-[__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'

The interesting thing is that it is not running as part of a bigger code but runs fine on a standalone basis.

A: 

The instance that it's sending the actionSheet:clickedButtonAtIndex: message to seems to think that it's of type NSData (of CFData). This suggests to me that the instance of self has probably been deallocated before the button is pressed.

Adding the delegate doesn't retain it, so you need to keep it around as long as the UIActionSheet is going to be visible.

Stephen Darlington
Stephen Darlington..you are such a darling...i was popping to root view controller before handling the action sheet... thanks a lot man..
Bogus Boy