简体   繁体   中英

presenting View Controller from AppDelgate

I tried have an application with UTabBarController in storyboard.

It displayed fine. however, I would like also to show firstTimViewController if user launch app for first time. hence, I need to show this view on didFinishLaunchingWithOptions in Appdelgate.

I've used below code:

UIStoryboard *storyboard = window.rootViewController.self.storyboard;
    StartupViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"StartupTableIdentifier"];
    [self.window.rootViewController presentModalViewController:svc animated:NO];

it gives me the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target .'

Have you set up the storyboard for the app? The name of the storyboard should match. Click on the project, click on the target, and verify in the summary tab that the Main Scoreboard name matches the name of the .storyboard in the project.

To make sure you have an inital view controller, make sure inital view controller is checked:

在此输入图像描述

Why not just have an NSUserDefaults setting that you set from the firstTimViewController (after it is dismissed) and just check for that setting in the Storyboard's rootVC (The first TabBar VC). When the app launches for the first time, check and see if the user has seen and acknowledged that firstTimeVC and if not, present it from the TabBar VC.

I would leave the AppDelegate alone and do the logic in the TabBar VC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM