我有一个应用程序,如果它在后台运行时间过长,我会在其中重新启动该应用程序。当用户在分配的时间后打开应用程序时,会发生重新初始化,并在获取所需数据时显示启动屏幕。当我从服务器获取数据时,我设置了 window.rootViewController
属性为新值。如果旧的 Root View Controller 有一个以模态方式呈现的 View Controller ,并且在重新初始化发生时正在显示该 View Controller ,则不会在 View Controller 上调用 dealloc(我已经通过将 NSLog 放在 dealloc 中进行了测试方法)。在没有显示模态视图 Controller 的情况下,dealloc 会按预期调用。
有谁知道解决这个问题?我不确定这是苹果的错误,还是我需要自己处理的事情。
最佳答案
我想出的解决方案是在设置 RootViewController 之前,我调用
- (void)_dismissRootViewControllersModalViewsIfAny {
UIViewController *rootViewController = self.window.rootViewController;
if (rootViewController.presentedViewController || rootViewController.presentingViewController)
{
[rootViewController dismissViewControllerAnimated:NO completion:nil];
}
}
这是我创建的一个方法,它确保如果有一个模态视图 Controller 要关闭,它将被关闭。
关于ios - 在显示模态视图后设置 rootViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31485776/