我有两个UIBarButtonItem
,它们都在我的iOS 8应用程序中打开了一个带有导航控制器的弹出窗口。两者都是使用storyboards
设置的,类型为Present As Popover
,"动画"设置为true。"Anchor"设置为相应的UIBarButtonItem
。
在代码中,这是在呈现popover/执行segue之前的配置。
override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == SEGUE_ID_ADD_ACTION {
if let actionViewController = (segue.destinationViewController as! UINavigationController).topViewController as? ActionViewController {
let newAction = Action()
actionViewController.selectedAction = newAction
actionViewController.delegate = self
}
}
else if segue.identifier == SEGUE_ID_FILTER {
let controller = (segue.destinationViewController as! UINavigationController).topViewController as! FilterViewController
controller.delegate = self
controller.setup(filter)
segue.destinationViewController.popoverPresentationController!.delegate = controller
}
}
显示的两个视图控制器类都没有更多的popover特定代码,只不过:
let size = CGSizeMake(320, 460)
self.navigationController?.preferredContentSize = size
在视图中将出现
我遇到的问题是,当弹出窗口A出现时,我按下按钮打开弹出窗口B。日志中显示了一个错误,但什么也没发生。最好弹出窗口B应该显示或至少隐藏弹出窗口B(类似于点击弹出窗口之外的任何其他地方)。日志错误:
Warning: Attempt to present <UINavigationController: 0x7fbdac027000> on <xxx.ActionListViewController: 0x7fbdac075000> which is already presenting (null)
添加
self.navigationController?.popoverPresentationController?.passthroughViews = nil
在popover中的包含viewcontroller中,至少修复了这样的问题,即当单击navigatonitem中的另一个按钮时,确实会触发其他popover的关闭。