iOS Present modal view controller on startup without flash

前端 未结 9 1158
囚心锁ツ
囚心锁ツ 2020-12-08 00:53

I\'d like to present modally, at first startup, a tutorial wizard to the user.

Is there a way to present a modal UIViewController on application startup

9条回答
  •  遥遥无期
    2020-12-08 01:03

    This is how I do it with storyboards and it works with multiple modals. This example has 3. Bottom, middle, and top.

    Just be sure to have the storyboardID of each viewController set correctly in interface builder.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        BottomViewController *bottomViewController = [storyboard instantiateViewControllerWithIdentifier:@"BottomViewController"];
        UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
        [window setRootViewController:bottomViewController];
        [window makeKeyAndVisible];
    
        if (!_loggedIn) {
            MiddleViewController *middleViewController = [storyboard instantiateViewControllerWithIdentifier:@"middleViewController"];
            TopViewController *topViewController = [storyboard instantiateViewControllerWithIdentifier:@"topViewController"];
    
            [bottomViewController presentViewController:middleViewController animated:NO completion:nil];
            [middleViewController presentViewController:topViewController animated:NO completion:nil];
    
        }
        else {
            // setup as you normally would.
        }
    
        self.window = window;
    
        return YES;
    }
    

提交回复
热议问题