Getting Initial View Controller from Storyboard inside the App Delegate

我们两清 提交于 2019-12-04 05:53:22
AppleDelegate

Be sure you have tick marked the

is initial ViewController

option for UINavigationController in storyBoard

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UINavigationController * myStoryBoardInitialViewController = [storyboard instantiateInitialViewController];

Sebastian, I'm not sure why you would want to start the initial view controller manually - all my projects (which all use storyboards) do this automatically if you ticked "Use Storyboards" on the second screen in the "New Project" wizard.

Maybe you need to mark the storyboard scene as inital? This can be done in the scene's attribute inspector by ticking the "Is Initial View Controller" - rather obviously named.

And then - if you really have a unusual setup which requires you to access the scenes manually, you can use the following:

UIStoryboard *sb = [UIStoryboard storyboardWithName: "StoryboardName"
                                             bundle: [NSBundle mainBundle]];
UIViewController *vc = [sb instantiateInitialViewController];

(Beware - no code completion here, so check spelling again.)

Or maybe I am getting your question completely wrong..? Happy hacking!

In my app i have tabBar

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

TabBarController *tabBar = [storyBoard instantiateViewControllerWithIdentifier:@"TabBarController"];

_window.rootViewController = tabBar;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!