2014-09-04 131 views
1

每当应用程序来自applicationDidEnterBackground方法中的背景时,我需要从appDelegate中显示一个ViewController。从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

什么是'presentsByAppDelegate' – meda 2014-09-04 21:25:11

+0

它是一个布尔我设置,所以我知道它是从AppDelegate提供的,因为我还在每次启动应用程序时提供安全检查,只有验证后我会调用popToRootViewController并且它可以工作。 – 2014-09-04 21:26:55

+0

马科斯,你使用故事板 – meda 2014-09-04 21:30:10

回答

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]; 
+0

如何从securityCheckDone方法中解雇它? – 2014-09-04 21:47:13

+1

我不知道你在那个方法里有什么,但是如果你在安全控制器中,你所要做的就是'[self dismissViewControllerAnimated:YES completion:nil];'它会显示前一个控制器在栈上 – meda 2014-09-04 21:49:49

+0

谢谢梅达,你为我澄清了一些事情=] – 2014-09-04 21:53:25

0

您可以从应用程序中调用这个中:didFinishLaunchingWithOptions

注:所有故事板 “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]; 
相关问题