How can I disable the main toolbar when displaying a popover using modalInPopover?
Asked Answered
I

3

6

I'm displaying a popover with the contained view controller having the modalInView property set. I need the user to enter a response here before continuing.

While this disables most of my user interface controls, it does disable the toolbar buttons on the main app. I don't want the user to interact with the application before selecting an item in the popover and closing it.

Am I missing something clever here - i.e. that would disable the toolbar by default? Why does it remain active? Is there some user interface guidelines that require it?

Should I just set the toolbar to disallow user interaction, or is that messy?

Ingraham answered 12/7, 2011 at 23:19 Comment(0)
A
6

It seems like iOS adds the bar as a "passthrough view" for the popover, when you present it from UIBarButtonItem.

Just set to nil passthroughViews property of UIPopoverController after presenting it, like this:

[self.myPopover presentPopoverFromBarButtonItem:some_item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{ self.myPopover.passthroughViews = nil; });
Ashur answered 19/7, 2013 at 16:44 Comment(2)
Lifesaver, for sure. I can't even conceive of why Apple would do this by default, since it's a guaranteed crash whenever you tap the bar button item again.Malkamalkah
On iOS8 you need to set the passthroughViews in another runloop to get it to work. More info here.Galling
D
2

Use -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated] instead, which doesn't enable toolbar interaction by default. For example, if presenting from a UIBarButtonItem with a customView property set:

[barButtonItem presentPopoverFromRect:barButtonItem.customView.bounds inView:barButtonItem.customView permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];`
Drawers answered 5/11, 2014 at 16:24 Comment(0)
S
1

What I found working best is what you mention as possibility in your question:

-(void)showMyPopover
{
    ....
    self.myToolBar.userInteractionEnabled=NO;
    [self.myPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]
}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    self.myToolBar.userInteractionEnabled=YES;
    ...
}
Snatch answered 1/9, 2012 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.