swift 4、XCode 9.4
在 UIAlertController 完成(或什至接近完成)时,我无法弹出回到堆栈的根。
要求是向用户显示确认,然后直接转换回“主页”页面。当我尝试时,我总是得到类似的东西:
popToViewController:transition: called on
<UINavigationController 0x7fc4fe85f000>
while an existing transition or presentation is occurring; the navigation stack will not be updated.
我理解我想的概念。 UIAlertController 处于控制之中,或者导航 Controller 的控制不足以弹出。好的,因为我已经完成了,所以有些道理。但我不知道如何在不进入的情况下触发我的转变。
@IBAction func doneAction(_ sender: Any) {
if verifyDoneProperly() {
let alert = UIAlertController(title: "Complete", message: "Good Job", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: {
if let nav = self.navigationController {
nav.popToViewController(select, animated: true)
}
})
}
}
FWIW,当我指定 View Controller 时它也不起作用。
我已仔细阅读 this answer但没有什么能真正帮助我(AFAIK)。
我真正想做的唯一一件事就是向根 Controller 发送一条消息,并让它在转换回来后显示警报(可能检查 viewWillAppear
中的标志)
肯定有一个正确的方法来做到这一点。任何人都可以提出建议吗?
重要说明:虽然我有 Storyboard,但我不能在这里使用 segues。到“worker” View Controller 的转换以编程方式完成,并根据当前状态进行选择。
最佳答案
我不确定在 View Controller 仍在呈现其他内容时弹出它是不是最好的主意。并且 present
的 completion
不会在 View Controller 被关闭后执行,只会在它完成呈现(即在屏幕上可见)后执行。
您可以在您的 OK 操作的 处理程序
中弹出您的 View Controller ——它将在您的 View Controller 不再显示警报后调用。
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
self.navigationController?.popToViewController(select, animated: true)
}))
关于ios - 无法从警报完成 : 弹出导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50934347/