Question

I have an actionsheet that is created from an UIBarButtonItem.

The bar button item programmaticly added when a view controller that is in a tab bar controller that is in a nav controller is show

- navigation controller
     -tab bar controller
          - view controller (bar button item created in viewdidload and shown in viewwillappear)

The actionsheet loads and displays correctly, the problem is to do with how it is dismissed. It dismisses correctly if i tap anywhere within the view but not when I tap on the navigation bar and this means that i can tap the UIBarButtonItem multiple times and actionsheets are created and overlayed.

I know I could do some logic to see if the actionsheet is being displayed and not recreate it and I could also add some logic to viewwilldisappear to manually remove the actionsheet but was wondering why it isn't working out of the box

Was it helpful?

Solution 2

I ended up adding some logic to the viewWillDisappear function to hide the actionsheet if it is showing.

I also had to add some other code to the bar button click action so that if tapped once the actionsheet is displayed, another actionsheet isn't overlayed.

OTHER TIPS

I had the same problem with a UIActionSheet being shown from a UIBarButtonItem where the sheet wasn't being dismissed when tapping the back button in UINavigationController.

I implemented the solution described by @updog

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    if ([actionSheet isVisible]) {
        [actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    }
}

The delegate isn't called when dismissWithClickedButtonIndex is executed, so the index doesn't matter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top