0

我有一个由标签栏制作的 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];
}

但是当新视图出现时,它会覆盖底部的标签栏。我该如何解决这个问题?

4

1 回答 1

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 中添加导航控制器

于 2013-04-24T08:20:42.603 回答