【问题标题】:UIViewController not being presented due to another being recently dismissedUIViewController 由于另一个最近被解雇而没有被呈现
【发布时间】:2015-11-12 18:22:16
【问题描述】:

我有一个视图控制器MainViewController,它(通过按钮)允许用户以模态方式呈现/关闭另一个InventoryViewController

第三个视图控制器CallViewcontroller 然后以特定的时间间隔从MainViewController 以编程方式呈现。在此之前,InventoryViewController 会被解除。

如果InventoryViewController 从未出现,CallViewController 会毫无问题地出现。

如果InventoryViewControllerCallViewController 启动时可见/存在,那么似乎也没有任何问题。

但是如果 InventoryViewController 出现然后被用户手动关闭,在任何时候,当 CallViewController 出现时,应用程序部分冻结并且控制台抛出错误 -

Warning: Attempt to present <CallViewController: 0x17e31bb0> on <MainViewController: 0x18d3fc00> whose view is not in the window hierarchy!

MainViewController 启动InventoryViewController 的代码:

[self performSegueWithIdentifier:@"segueToInventoryView" sender:self];

MainViewController 内的按钮中解除InventoryViewController 的代码:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

在出现CallViewController 之前以编程方式从MainViewController 中解散InventoryViewController 的代码:

[self dismissViewControllerAnimated:NO completion:nil];

(我还使用计时器来延迟呈现CallViewController 的方法,以确保InventoryViewController 已被正确关闭)

我猜这个错误是说我不能从MainViewController 显示一个模态,因为它不在堆栈的顶部,这表明InventoryViewController 没有被正确地解除。

最初我的代码是为 iOS7 编写的,现在 BaseSDK 是 iOS9(我通常在一年后返回这个项目和 iOS 编程)。据我所知,这个问题以前没有发生过。那么这是由 iOS8/9 带来的变化引起的,还是这里发生了其他事情?

任何帮助表示赞赏。

【问题讨论】:

    标签: ios cocoa-touch


    【解决方案1】:

    找到了解决方案,我在MainViewController 中有一个标志,用于检查InventoryViewController 是否已被解除,但设置不正确。这导致[self dismissViewControllerAnimated:NO completion:nil] 被调用两次,第二次它实际上是通过将调用发送给它的父级来关闭MainViewController

    因此,可以在呈现和呈现的视图控制器上调用 [self dismissViewControllerAnimated:NO completion:nil] 这一事实可能需要注意。

    上面列出的代码似乎在 iOS8/9 中运行良好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-28
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多