[英]Presenting ViewController from appDelegate
每当应用程序来自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
}
当下
- (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];
您可以从application: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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.