我有一个视图控制器MainViewController
,它(通过按钮)允许用户以模态方式显示/解除另一个InventoryViewController
。
然后以特定的时间间隔从CallViewcontroller
以编程方式呈现第三个视图控制器MainViewController
。在此之前,InventoryViewController
被驳回。
如果永远不会显示InventoryViewController
,则会CallViewController
没有任何问题。
如果InventoryViewController
启动时CallViewController
可见/存在,那么似乎也不会出现任何问题。
但是如果出现InventoryViewController
,那么用户手动关闭,在任何时候,当CallViewController
出现时,应用程序会部分冻结并且控制台会抛出错误 -
Warning: Attempt to present <CallViewController: 0x17e31bb0> on <MainViewController: 0x18d3fc00> whose view is not in the window hierarchy!
从InventoryViewController
启动MainViewController
的代码:
[self performSegueWithIdentifier:@"segueToInventoryView" sender:self];
从InventoryViewController
MainViewController
的代码
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
在InventoryViewController
出现之前,MainViewController
以编程方式解除CallViewController
的代码:
[self dismissViewControllerAnimated:NO completion:nil];
(我还使用计时器来延迟显示CallViewController
的方法,以确保InventoryViewController
已被正确解散)
我猜错了是说我无法提供MainViewController
的模态,因为它不在堆栈的顶部,表明{{1}没有得到适当的解雇。
最初我的代码是为iOS7编写的,现在BaseSDK是iOS9(一年后我回到这个项目和iOS编程)。据我所知,这个问题以前没有发生过。这是由iOS8 / 9带来的变化引起的,还是会发生其他事情?
任何帮助表示感谢。
答案 0 :(得分:0)
找到解决方案,我在MainViewController
中有一个标记,用于检查InventoryViewController
是否已被解除,但未正确设置。这导致[self dismissViewControllerAnimated:NO completion:nil]
被调用两次,第二次实际上是通过将呼叫发送给它的父母来解雇MainViewController
!
因此,可以在呈现和呈现的视图控制器上调用[self dismissViewControllerAnimated:NO completion:nil]这一事实可能需要注意。
上面列出的代码似乎在iOS8 / 9
中都能正常工作