Programmatically call storyboard in delegate

被刻印的时光 ゝ 提交于 2019-12-12 07:59:21

问题


I'm trying to programmatically call my storyboard. My storyboard consists of the following:

[Navigation Controller] -> [MainMenuView] -> [DetailsView]

The "MainMenu" identifier was placed in the [MainMenuView]

The problem i'm having is the screen showing blank. What do i need to do?

Thanks.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{       
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    MainMenuView *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainMenu"];

    return YES
}

回答1:


You need to first create the window manually and then add the rootViewController in it (the previous answer was almost correct):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    UIViewController *mainViewController = [storyboard instantiateInitialViewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = mainViewController;
    [self.window makeKeyAndVisible];

    return YES;
}



回答2:


You need to set the rootViewController property of your application's window:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{       
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    MainMenuView *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainMenu"];

    self.window.rootViewController = rootViewController;

    return YES;
}


来源:https://stackoverflow.com/questions/9828217/programmatically-call-storyboard-in-delegate

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