0

I have a universal app and have an action sheet with a few buttons. When I tap the add button (navigationItem.right) I want it to show in a popoever. It does this correctly, however, with the actionSheet tied to the barbutton item, it allows me to continually tap the add button and have more popup.

I thought tapping outside the popover would dismiss this...

- (IBAction)ShowItemAdd:(id)sender
{
    addActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:[dataObj.preferences objectForKey:@"appts_name"], @"Reserve", nil];
    if ([[UIDevice currentDevice] isPad]) {
        [addActionSheet showFromBarButtonItem:[[self navigationItem] rightBarButtonItem] animated:YES];
    } else {
        [addActionSheet showInView:self.view];
    }
}

Why is this not auto dismissing if I have it bound to the barbutton item?

EDIT

Tapping anywhere in the navigationItem bar (blue bar) at the top will not close the actionSheet, however tapping outside of the nav controller, will dismiss the actionsheet.

enter image description here

Bot
  • 11,868
  • 11
  • 75
  • 131

1 Answers1

1

In your method you should first check to see whether your actionsheet is already visible, and if it is, dismiss it instead of creating a new actionsheet.

- (IBAction)ShowItemAdd:(id)sender
{
    if ([addActionSheet isVisible]) {

        [addActionSheet dismissWithClickedButtonIndex:[addActionSheet cancelButtonIndex] animated:YES];

    } else {

        addActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:[dataObj.preferences objectForKey:@"appts_name"], @"Reserve", nil];
        if ([[UIDevice currentDevice] isPad]) {
            [addActionSheet showFromBarButtonItem:[[self navigationItem] rightBarButtonItem] animated:YES];
        } else {
            [addActionSheet showInView:self.view];
        }
    }
}
jonkroll
  • 15,682
  • 4
  • 50
  • 43
  • isVisible always returns false; – Bot Aug 21 '12 at 15:56
  • Do you have a property on your viewController to store the reference to the actionSheet? Try changing `addActionSheet` to `self.addActionSheet` – jonkroll Aug 21 '12 at 17:24
  • I do have addActionSheet as a property. I changed it to `self.addActionSheet` and still same thing. – Bot Aug 21 '12 at 17:32
  • I apologize I had the is visible after I was reinstantiating the addActionSheet. I moved it to the top and it works. Thanks! – Bot Aug 21 '12 at 17:57