我有一个由标签栏制作的x-code项目。在AppDelegate.m
我为每个视图创建了三个按钮:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3=[[[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil]autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
当我在第一个视图时,我想创建一个调用另一个视图的按钮:
-(IBAction)btnPush{
[[self navigationController] pushViewController:newView animated:YES];
}
但是当新视图出现时,它会覆盖按钮上的标签栏。我该怎么做才能解决问题?
答案 0 :(得分:1)
而不是在UIViewController
中添加UITabBarController
,而是添加UINavigationController
,如下所示
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3=[[[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil]autorelease];
现在将ViewController添加到NavigationController
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
self.tabBarController.viewControllers = @[navController1, navController2,navController3];
它将在TabBarController中添加导航控制器