我为每个标签创建了一个带有4个标签和4个viewControllers的标签应用程序。我尝试在FirstViewController中添加导航栏,它只添加导航栏,内容区域显示为黑色。
我的标签和视图控制器代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2,*viewController3, *viewController4;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[VKFirstViewController alloc] initWithNibName:@"VKFirstViewController_iPhone" bundle:nil];
viewController2 = [[VKSecondViewController alloc] initWithNibName:@"VKSecondViewController_iPhone" bundle:nil];
viewController3 = [[VKThirdViewController alloc] initWithNibName:@"VKThirdViewController_iPhone" bundle:nil];
viewController4 = [[VKFourthViewController alloc] initWithNibName:@"VKFourthViewController_iPhone" bundle:nil];
} else {
viewController1 = [[VKFirstViewController alloc] initWithNibName:@"VKFirstViewController_iPad" bundle:nil];
viewController2 = [[VKSecondViewController alloc] initWithNibName:@"VKSecondViewController_iPad" bundle:nil];
viewController3 = [[VKThirdViewController alloc] initWithNibName:@"VKThirdViewController_iPad" bundle:nil];
viewController4 = [[VKFourthViewController alloc] initWithNibName:@"VKFourthViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3, viewController4];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
答案 0 :(得分:1)
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UINavigationController *firstNav = [[UINavigationController alloc]init];
UINavigationController *secondNav = [[UINavigationController alloc]init];
UIViewController *viewController1, *viewController2,*viewController3, *viewController4;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[VKFirstViewController alloc] initWithNibName:@"VKFirstViewController_iPhone" bundle:nil];
viewController2 = [[VKSecondViewController alloc] initWithNibName:@"VKSecondViewController_iPhone" bundle:nil];
viewController3 = [[VKThirdViewController alloc] initWithNibName:@"VKThirdViewController_iPhone" bundle:nil];
viewController4 = [[VKFourthViewController alloc] initWithNibName:@"VKFourthViewController_iPhone" bundle:nil];
firstNav.viewControllers = @[viewController1, viewController2,viewController3, viewController4];
} else {
viewController1 = [[VKFirstViewController alloc] initWithNibName:@"VKFirstViewController_iPad" bundle:nil];
viewController2 = [[VKSecondViewController alloc] initWithNibName:@"VKSecondViewController_iPad" bundle:nil];
viewController3 = [[VKThirdViewController alloc] initWithNibName:@"VKThirdViewController_iPad" bundle:nil];
viewController4 = [[VKFourthViewController alloc] initWithNibName:@"VKFourthViewController_iPad" bundle:nil];
secondNav.viewControllers = @[viewController1, viewController2,viewController3, viewController4];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[firstnav, secondNav];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
答案 1 :(得分:0)
我在navigationController中添加了viewController1,并将此navigationController对象添加到tabBarController。现在它工作正常。请参阅https://stackoverflow.com/a/14030551/1119440
UIViewController *tmpviewController1, *viewController2,*viewController3, *viewController4;
UINavigationController *viewController1;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//UIViewController *tmpViewController1 = [[[YourViewController alloc] init] initWithNibName:@"YourViewController" bundle:nil];
tmpviewController1 = [[VKFirstViewController alloc] initWithNibName:@"VKFirstViewController_iPhone" bundle:nil];
viewController1 = [[UINavigationController alloc] initWithRootViewController:tmpviewController1];
//viewController1 = [[VKFirstViewController alloc] initWithNibName:@"VKFirstViewController_iPhone" bundle:nil];
viewController2 = [[VKSecondViewController alloc] initWithNibName:@"VKSecondViewController_iPhone" bundle:nil];
viewController3 = [[VKThirdViewController alloc] initWithNibName:@"VKThirdViewController_iPhone" bundle:nil];
viewController4 = [[VKFourthViewController alloc] initWithNibName:@"VKFourthViewController_iPhone" bundle:nil];
} else {
viewController1 = [[VKFirstViewController alloc] initWithNibName:@"VKFirstViewController_iPad" bundle:nil];
viewController2 = [[VKSecondViewController alloc] initWithNibName:@"VKSecondViewController_iPad" bundle:nil];
viewController3 = [[VKThirdViewController alloc] initWithNibName:@"VKThirdViewController_iPad" bundle:nil];
viewController4 = [[VKFourthViewController alloc] initWithNibName:@"VKFourthViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3, viewController4];