问题
How do you dismiss a popover from within a navigation stack. I have a navigation controller as the root controller of the popover and 2 taes vies in the stack. So that the first table view pushes the second and the second should dismiss the popover. I could pass a reference from table to table of the popover though this seems wrong. What is the preferred way of dismissing a popover after navigated through different controllers?
回答1:
In your appdelegate, add a new NSNotificationCenter observer:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hidePopover)
name:@"hidePopover"
object:nil];
Once you have that setup, add a new method within the appdelegate like so:
-(void)hidePopover{
[UIPopoverController dismissPopoverAnimated:YES];
}
This approach is great, because now you have things set up in such a way that you can close the popover from anywhere. You do this like so:
[[NSNotificationCenter defaultCenter] postNotificationName:@"hidePopover"
object:nil];
Hope this solves your conundrum,
Zane
来源:https://stackoverflow.com/questions/4779962/dismissing-a-uipopover