Reputation: 26068
I'm creating an app that has some UIBarButton items, some of which will launch a UIPopoverController when pressed. I'd like for this to disable anything from being able to be interacted with, which mostly happens by default. I've noticed, however, that other UIBarButtonItems within the same toolbar will still be active while the popover is active. I've tried to add:
[_popOver setPassthroughViews:nil];
prior to showing it, but the UIBarButtonItems are still able to be pressed while the pop over is shown. I realized I could disable the buttons, but I'd rather not have to do this as I'd have to introduce all kinds of unnecessary state while each kind of pop-over is open. Is there any way to have the pop-over be dismissed when anything is selected outside the pop-over (including other UIBarButtonItems)?
Basic code to repro the problem:
- (IBAction)rightButtonPressed:(id)sender {
UIViewController *vc = [[UIViewController alloc] init];
_popOver = [[UIPopoverController alloc] initWithContentViewController:vc];
[_popOver setPassthroughViews:nil];
[_popOver presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
- (IBAction)leftButtonPressed:(id)sender {
NSLog(@"Why am I active while pop-over is visible?");
}
Add both bar button items to the same navigation bar.
Upvotes: 1
Views: 417
Reputation: 26068
I'm an idiot, figured out the solution moments after posting this. It seems the call to presentPopoverFromBarButtonItem
automatically adds the navigation bar to the passthroughviews. Since I was clearing out before and not after presenting the UIPopoverView
, it was getting added back. A simple change of the order of the calls fixes the problem.
- (IBAction)rightButtonPressed:(id)sender {
UIViewController *vc = [[UIViewController alloc] init];
_popOver = [[UIPopoverController alloc] initWithContentViewController:vc];
[_popOver presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
//Call this *AFTER* presenting the popover
[_popOver setPassthroughViews:nil];
}
Upvotes: 1