Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically call storyboard in delegate

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
}
like image 471
RockBaby Avatar asked Mar 22 '12 18:03

RockBaby


2 Answers

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;
}
like image 157
sarfata Avatar answered Nov 03 '22 00:11

sarfata


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;
}
like image 43
jonkroll Avatar answered Nov 02 '22 23:11

jonkroll