每次应用程序来自applicationDidEnterBackground方法的后台时,我都需要从appDelegate显示一个ViewController。
* securityCheck会提示用户输入的密码与iOS中的普通密码非常相似。验证密码后,我在securityCheck中调用dimissViewControllerAnimated,我的空白UINavigationController,因为视图是从appDelegate呈现的,我没有提供视图的记录,所以我不能popToRootViewController。
我的问题是如何正确解除SecurityCheckViewController,以便在应用程序进入后台之前显示用户所在的ViewController。
这是我的代码:
此方法在AppDelegate.m
中调用- (void)securityCheck {
SecurityCheckViewController *securityCheck = [[SecurityCheckViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:securityCheck];
[securityCheck presentedByAppDelegate:YES];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
}
然后在SecurityCheckViewController.m里面我有
- (void)unlockWasSuccessfulForPadLockScreenViewController:(ABPadLockScreenViewController *)padLockScreenViewController {
[self.appDelegate securityCheckDone];
[padLockScreenViewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"Sucsessfull Unlock");I'm
}
答案 0 :(得分:2)
<强>当前强>
- (void)securityCheck {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
SecurityCheckViewController *securityCheck = [storyboard instantiateViewControllerWithIdentifier:@"securityCheckView"];
[self.window.rootViewController presentViewController:securityCheck animated:NO completion:nil];
}
<强>关闭强>
[self dismissViewControllerAnimated:YES completion:nil];
答案 1 :(得分:0)
您可以从应用程序中调用此方法:didFinishLaunchingWithOptions
注意:属性检查器上的所有storyBoard“initialViewControllers”复选框都已关闭
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:@"Registration" bundle:nil];
RegisterViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"RegisterViewController"];
//this is key else you get a black screen
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];