In AppDelegate möchte ich einen TabBarController als rootViewController setzen.Wie setze ich einen tabBarController als rootViewController
Ich habe versucht:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
Ich habe auch versucht:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
self.window.rootViewController = tabBarController;
aber es sagt:
konnte nicht die Standard-View-Controller für UIMainStoryboardFile 'Main' instanziiert - vielleicht ist der angegebene Einstiegspunkt nicht gesetzt?
Mein vollständiger Code in AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// Movies
MediaListViewController *moviesVC = (MediaListViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MediaList"];
moviesVC.title = @"Movies";
moviesVC.tabBarItem.image = [[UIImage imageNamed:@"superman"] imageWithRenderingMode:(UIImageRenderingModeAlwaysTemplate)];
UINavigationController *moviesNC = [[UINavigationController alloc] initWithRootViewController:moviesVC];
moviesNC.navigationBar.barTintColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
moviesNC.navigationBar.tintColor = [UIColor yellowColor];
moviesNC.navigationBar.barStyle = UIBarStyleBlack;
//DVDs
MediaListViewController *dvdsVC = (MediaListViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MediaList"];
dvdsVC.title = @"DVDs";
dvdsVC.tabBarItem.image = [[UIImage imageNamed:@"hulk"] imageWithRenderingMode:(UIImageRenderingModeAlwaysTemplate)];
UINavigationController *dvdsNC = [[UINavigationController alloc] initWithRootViewController:dvdsVC];
dvdsNC.navigationBar.barTintColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
dvdsNC.navigationBar.tintColor = [UIColor yellowColor];
dvdsNC.navigationBar.barStyle = UIBarStyleBlack;
tabBarController.viewControllers = @[moviesNC, dvdsNC];
tabBarController.tabBar.barTintColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
[self.window makeKeyAndVisible];
return YES;
}
was ist bei deinem zweiten Versuch passiert? UITabBarController * tabBarController = [[UITabBarController alloc] init]; –
Hallo @AnilVarghese, Es sagt auch dasselbe wie die erste. – Khuong
In Ihrem main.storyboard, haben Sie den ersten Controller (möglicherweise Tabbar-Controller) als 'initialViewController' gesetzt –