我想在我的应用程序启动时呈现一个模式视图控制器(用于登录屏幕),以及在用户点击主页按钮然后重新启动应用程序后它再次变为活动状态时。
我首先尝试在根视图控制器的viewDidAppear:
方法中呈现模态视图。这在应用程序首次启动时效果很好,但当应用程序再次激活时不会调用此方法。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self presentModalView];
}
- (void)presentModalView {
if(![AuthenticationService sharedInstance].isAuthenticated) {
_modalVC = [self.storyboard instantiateViewControllerWithIdentifier:self.modalViewControllerIdentifier];
_modalVC.delegate = self;
[self presentViewController:_modalVC animated:YES completion:nil];
}
}
接下来,我尝试在方法中从我的应用程序委托中调用它applicationDidBecomeActive:
。
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
ModalPresentingUISplitViewController *splitViewController = (ModalPresentingUISplitViewController *)self.window.rootViewController;
[splitViewController presentModalView];
}
这在表面上似乎工作正常,但我Unbalanced calls to begin/end appearance transitions for <ModalPresentingUISplitViewController: 0x7251590>
在日志中收到警告。我觉得我在 UISplitView 完成呈现之前以某种方式呈现模态视图,但我不知道如何解决这个问题。
当应用程序变为活动状态时,我如何“自动”从我的根视图控制器呈现模态视图,并在“正确”时刻执行,以免使我的拆分视图控制器失衡?