Dismissing a UIpopover

拥有回忆 提交于 2020-01-24 00:00:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!