ingenspor
ingenspor

Reputation: 932

Make UITabBarController the root view controller

I made an empty application, then later I and added a UITabBarController in the Storyboard. Then I checked it as the initial viewcontroller and connected two NavigationControllers to represent the tabs. But if I run the app now it says that "Application windows are expected to have a root viewcontroller at the end of application launch." and shows a white screen.

My AppDelegate looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

I have to add the TabBarController as the main window, but how to do this? If TabBarController was made programmatically I would have figured it but how to when it's created in storyboard? Can I make a property for it in AppDelegate? How to hook it in storyboard in that case?

Upvotes: 1

Views: 2822

Answers (1)

Michal Zaborowski
Michal Zaborowski

Reputation: 5099

You can hook storyboard inside your target settings Storyboard Then make sure that your UITabBarController inside of your storyboard is initial UIViewController Initial View Controller. You can also use this code:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *initialViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"IdentifierOfYourViewController"];
self.window.rootViewController = initialViewController;

Upvotes: 3

Related Questions