Search code examples
iphoneobjective-cuiactionsheet

UIActionSheet, how to dismiss it with a single click?


UIActionSheet, how to dismiss it with a single click? I have to click a button 2 times so it gets dismissed, what should I do to make it dismissble after the first click?! Here is my code:

-(void)buttonHeld:(id)sender
{



    UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Delete Contact?!" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles: nil];

    popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    [popupQuery showInView:self.view];
    [popupQuery release];




}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {


  if (buttonIndex == 0) {

 NSLog(@"Delete button clicked Button Clicked");


    else if (buttonIndex == 1) {

   NSLog(@"Cancel Button Clicked");
   } 

}

Solution

  • It took me a few taps to get it to cancel as well. The problem ended up being which view I attached it to.

    [action showInView:self.view];
    

    self.view was only referenced in IB. I changed it to a different view and it worked.