Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当现有转换或呈现正在发生时;导航堆栈将不会更新_Ios_Swift - Fatal编程技术网

Ios 当现有转换或呈现正在发生时;导航堆栈将不会更新

Ios 当现有转换或呈现正在发生时;导航堆栈将不会更新,ios,swift,Ios,Swift,我遇到了以下警告: pushViewController:animated:在激活现有转换或演示时调用 发生;导航堆栈将不会更新 试图从UIAlertController完成块调用navigationController?.popViewControllerAnimated(false)。此警告表示您试图错误使用UINavigationController: pushViewController:animated:在现有转换或演示发生时调用;导航堆栈将不会更新 您在评论中提到,您正试图pop V

我遇到了以下警告:

pushViewController:animated:在激活现有转换或演示时调用 发生;导航堆栈将不会更新


试图从
UIAlertController
完成块调用
navigationController?.popViewControllerAnimated(false)

此警告表示您试图错误使用
UINavigationController

pushViewController:animated:在现有转换或演示发生时调用;导航堆栈将不会更新

您在评论中提到,您正试图
pop
ViewController
使用

navigationController?.popViewControllerAnimated(false)
UIAlertController
的内部完成块。因此,您试图从错误的视图中展开,
UIAlertController
不是
UINavigationController
堆栈的一部分

首先尝试关闭
UIAlertController
,然后弹出当前
ViewController
。换句话说,从
completion
块中删除
pop
,并将其放入
OK
块中。或在发出警报前使用
展开
segue

另一种可能性是,您在<代码>情节提要中有一个未使用或相同的副本。因此,如果
故事板
按钮触发了
展开
操作,请选择此按钮并检查
连接检查器
并删除不需要的连接

例如:在我的情况下,红色的x标记是不必要的。

我正在使用异步调度它的工作方式。我试图向后导航,但没有成功,因为导航堆栈将不会更新。

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)!
        })
    })

我的解决方案是先调用dismissViewControllerAnimated:然后从导航堆栈中弹出viewcontroller这对我来说很有用:-

[self dismissViewControllerAnimated:false completion:nil];
[myNavigationControllerInstance popToRootViewControllerAnimated:true]; // myNavigationControllerInstance = Your Navigation Controller Instance

我使用DispatchQueue.main.asyncAfter解决了这个问题,在UIAlertController的转换完成后调用popviewcontroller

1) 显示警惕

2) 延迟后调用pop viewcontroller

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
    self.navigationController?.popToRootViewController(animated: true)
}

这不是最好的方法,但它有效

在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)

任何人都需要返回到以前的VC
使用此代码Swift5

    dismiss(animated: true) {
        // If you need call someFunction()
        self.someFunction()
        self.navigationController?.popViewController(animated: true)
    }

没有正确理解你的问题!把你的问题说清楚?我得到了这样一个警告:pushViewController:animated:在现有转换或演示发生时启用;导航堆栈将不会更新。我正在警报控制器操作的完成句柄中调用navigationController?.popViewControllerAnimated(false)Hello@SidduHala获取有关上述问题的任何更新或任何要解决的想法。完美。很容易忘记警报是视图控制器。