代码之家  ›  专栏  ›  技术社区  ›  Marcos Curvello

从appDelegate呈现ViewController

  •  1
  • Marcos Curvello  · 技术社区  · 11 年前

    每次应用程序来自applicationDidEnterBackground方法的后台时,我都需要从appDelegate中显示ViewController。

    *securityCheck提示用户输入密码,这与iOS中的正常密码非常相似。验证密码后,我在securityCheck中调用dimissViewControllerAnimated,剩下的是空白的UINavigationController,因为视图是从appDelegate中显示的,我没有显示视图的记录,因此无法打开RootViewController。

    我的问题是如何正确地关闭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 
    }
    
    2 回复  |  直到 11 年前
        1
  •  2
  •   meda    11 年前

    目前

    - (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];
    
        2
  •  0
  •   Wayne    8 年前

    你可以从 应用程序: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];