How to present two consecutive UIPopoverControllers properly?
I want to present a custom menu inside a popover controller when the user taps on a UIButton. Then I want to present another menu, using the exact same approach when the user presses another button.
My problem is this: When the user presses the first button, the popover appears with my menu, and that'开发者_如何学Gos OK. But then when he presses the second button, instead of dismissing the first popover and then presenting the second one with the second menu, my app just dismisses the first popover. And then when the users presses the second button, the second popover appears. So, the user has to press two times in order to see the second menu.
Here is how I create the menu and the popover:
CascadeMenuViewController *cascadeMenuViewController = [[CascadeMenuViewController alloc] initWithNibName:@"CascadeMenuViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:cascadeMenuViewController];
[cascadeMenuViewController release];
navigationController.navigationBar.barStyle = UIBarStyleBlack;
_popoverMenuView = [[UIPopoverController alloc] initWithContentViewController:navigationController];
[navigationController release];
[_popoverMenuView presentPopoverFromRect:_currentlyTouchedButtonView.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
Here is how I dismiss the popover, when the user chooses sthg from the menu inside the popover:
if (_popoverMenuView) {
[_popoverMenuView dismissPopoverAnimated:YES];
[_popoverMenuView release];
_popoverMenuView = nil;
}
Can you tell me what I'm doing wrong?
Thx in advance...
What is happening is the following:
when the pop over is displayed, each tap outside of it will simply make the pop over to be dismissed, and will not be forwarded to other views;
you can override this mechanism by using the
passthroughViews
, a list of views which get the taps forwarded to them;it must be noted that when the forwarding happens (i.e., you tap on one of the views in
passthroughViews
), the pop over will not be dismissed automatically; so, in your case, you will have to dismiss on your own, and when the tap is on the button, you will open the second pop over.
From the Apple Documents:
When displayed, taps outside of the popover window cause the popover to be dismissed automatically. To allow the user to interact with the specified views and not dismiss the popover, you can assign one or more views to the passthroughViews property. Taps inside the popover window do not automatically cause the popover to be dismissed. Your view and view controller code must handle actions and events inside the popover explicitly and call the dismissPopoverAnimated: method as needed.
精彩评论