【问题标题】:While an existing transition or presentation is occurring; the navigation stack will not be updated当现有的过渡或演示发生时;导航堆栈不会更新
【发布时间】:2016-05-17 07:45:48
【问题描述】:

我遇到了这个警告:

pushViewController:animated: 在现有的过渡或演示时调用 发生;导航堆栈不会更新。

在尝试从 UIAlertController 完成块调用 navigationController?.popViewControllerAnimated(false) 时。

【问题讨论】:

  • 没有正确回答您的问题!
  • 把你的问题说清楚?
  • 我收到了这个警告:pushViewController:animated: 调用 而现有的过渡或演示正在发生;导航堆栈不会更新。
  • 我在警报控制器操作的完成处理程序中调用了 navigationController?.popViewControllerAnimated(false)
  • 你好@SidduHalake关于上述问题的任何更新或任何解决的想法。

标签: ios swift


【解决方案1】:

此警告表明您尝试错误地使用UINavigationController

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

您在 cmets 中提到您正在尝试 pop ViewController 使用

navigationController?.popViewControllerAnimated(false)

UIAlertController 的完成块内。因此,您正试图从错误的观点中解脱出来,UIAlertController 不是UINavigationController 堆栈的一部分

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

另一种可能性是,您在 storyboard 中有一个未使用或相同的副本。因此,如果unwinding 操作由storyboard 按钮触发,请选择此按钮并检查connectivity inspector 并删除不需要的连接。

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

【讨论】:

  • 完美。很容易忘记警报是视图控制器。
【解决方案2】:

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

1) 显示警报

2) 延迟后调用pop viewcontroller

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

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

【讨论】:

    【解决方案3】:

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

       

    【讨论】:

      【解决方案4】:

      我正在使用 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)!
              })
          })
      

      【讨论】:

        【解决方案5】:

        我的解决方案是先调用dismissViewControllerAnimated:然后从导航堆栈中弹出视图控制器,这对我有用:-

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

        【讨论】:

          【解决方案6】:

          任何人都需要返回 PreviousVC 使用此代码。 Swift5

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-05-17
            • 1970-01-01
            • 2010-11-22
            • 2022-12-18
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多