ios 当现有的过渡或演示正在发生时;导航堆栈不会更新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37270113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
While an existing transition or presentation is occurring; the navigation stack will not be updated
提问by Siddu Halake
I have encountered this warning:
我遇到了这个警告:
pushViewController:animated: called on while an existing transition or presentation is occurring; the navigation stack will not be updated.
pushViewController:animated: 在现有过渡或演示发生时调用;导航堆栈不会更新。
While trying to call navigationController?.popViewControllerAnimated(false)
from UIAlertController
completion block.
尝试navigationController?.popViewControllerAnimated(false)
从UIAlertController
完成块调用时。
采纳答案by Idan
This warning indicates that you are trying use UINavigationController
wrongly:
此警告表明您尝试使用UINavigationController
错误:
pushViewController:animated: called on while an existing transition or presentation is occurring; the navigation stack will not be updated
pushViewController:animated: 在现有过渡或演示发生时调用;导航堆栈不会更新
You mentioned in the comments that you are trying to pop
the
ViewController
using
您在评论中提到,您要pop
的
ViewController
使用
navigationController?.popViewControllerAnimated(false)
inside completion block of UIAlertController
. Therefore, you are trying to unwind from the wrong view, UIAlertController
is not part of the UINavigationController
stack.
的完成块内UIAlertController
。因此,您试图从错误的视图中放松,UIAlertController
而不是UINavigationController
堆栈的一部分。
Try and close the UIAlertController
first, then pop the current ViewController
. In other words, remove the pop
from the completion
block and put it inside the OK
block. or use unwind
segue before the alert.
尝试关闭第UIAlertController
一个,然后弹出当前的ViewController
. 换句话说,pop
从completion
块中移除并将其放入OK
块中。或unwind
在警报之前使用segue。
Another possibility, is that you have an unused or identical duplicate in storyboard
. Hence, if the unwinding
operation is triggered by storyboard
button, select this button and check the connectivity inspector
and removed unwanted connections.
另一种可能性是,您在storyboard
. 因此,如果unwinding
操作是由storyboard
按钮触发的,请选择此按钮并检查connectivity inspector
和删除不需要的连接。
回答by Meghs Dhameliya
I solved this using DispatchQueue.main.asyncAftercall popviewcontroller after the UIAlertController's Transition complete
在 UIAlertController 的转换完成后,我使用DispatchQueue.main.asyncAfter调用 popviewcontroller解决了这个问题
1) Show Alert
1) 显示警报
2) Call pop viewcontroller after delay
2)延迟后调用pop viewcontroller
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationController?.popToRootViewController(animated: true)
}
This is not best way, but it works!
这不是最好的方法,但它有效!
回答by Sourabh Kumbhar
Add the code of navigate controller on the ok action button handler. When Tap on ok button navigate the view controller
在 ok 操作按钮处理程序上添加导航控制器的代码。当点击确定按钮时导航视图控制器
let okActionBtn = UIAlertAction(title: "Ok", style: .default, handler: {
? ? ? self.navigationController?.popViewController(animated: true)
})
let cancelActionBtn = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alert.addAction(okActionBtn)
alert.addAction(cancelActionBtn)
self.present(alert, animated: true)
? ?
? ?
回答by Mr.Javed Multani
i am using dispatch_asyncand its working. i tried to navigate back but didn't worked because navigation stack will not be updated.
我使用 dispatch_async和其工作。我试图导航回来,但没有奏效,因为导航堆栈不会更新。
let destVC = self.storyboard?.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
self.presentViewController(destVC, animated: true, completion: {() -> Void in
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.navigationController?.popViewControllerAnimated(true)!
})
})
回答by tryKuldeepTanwar
My Solution would be to call dismissViewControllerAnimated: first and then pop the viewcontroller from navigation stack this works for me :-
我的解决方案是先调用dismissViewControllerAnimated:然后从导航堆栈中弹出viewcontroller,这对我有用:-
[self dismissViewControllerAnimated:false completion:nil];
[myNavigationControllerInstance popToRootViewControllerAnimated:true]; // myNavigationControllerInstance = Your Navigation Controller Instance