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
}
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;
}
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With