0

我是IOS的新手。在我的应用程序的主页中,有 3 个选项卡和 4 个按钮(使用导航控制器)。我在 appdelegate.m 中创建了一个 tabbarcontroller,如下所示:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.


//Initializing the view controllers
UIViewController *disController1 = [[DisController1 alloc]initWithNibName:@"DisController1" bundle:nil];
UIViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UIViewController *wishlistController = [[Wishlist alloc]initWithNibName:@"Wishlist" bundle:nil];
UIViewController *helpController = [[HelpController alloc]initWithNibName:@"HelpController" bundle:nil];
UIViewController *disController2 = [[DisController1 alloc]initWithNibName:@"DisController2" bundle:nil];


NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
[viewControllersArray addObject:disController1];
[viewControllersArray addObject:viewController];
[viewControllersArray addObject:wishlistController];
[viewControllersArray addObject:helpController];
[viewControllersArray addObject:disController2];



//Initializing the tab bar controller
UIImage *img = [UIImage imageNamed:@"SES_tab bar"];

CGSize newSize = CGSizeMake(SCRN_WIDTH, TABHEIGHT);

Common *common = [[Common alloc]init];
UIImage *newImage = [common imageResize:img andResizeTo:newSize];
[common setTabBarColorandImage:newImage];

tabController = [[UITabBarController alloc]init];


tabController.viewControllers = [NSArray arrayWithObjects:disController1, viewController,wishlistController,helpController,disController2 ,nil];

tabController.selectedIndex = 1;
UITabBarItem *firstTab = [[tabController.tabBar items]objectAtIndex:0];
UITabBarItem *lastTab = [[tabController.tabBar items]objectAtIndex:4];
[firstTab setEnabled:NO];
[lastTab setEnabled:NO];


UINavigationController *navCtrl = [[UINavigationController alloc]initWithRootViewController:tabController];
//navCtrl.navigationBarHidden = NO;

//[navCtrl.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
[navCtrl.navigationBar setBarStyle:UIBarStyleBlackTranslucent ];
[navCtrl.navigationBar.topItem setTitle:@"Home"];
[self.window addSubview:tabController.view];


self.window.rootViewController = navCtrl;
[self.window makeKeyAndVisible];
return YES;

TabBar 适用于我的主页。但我的问题是当我单击按钮时,Tab 栏不会出现在新视图中。我该如何实施?

4

1 回答 1

1

您应该为每个选项卡创建 UINavigationControllers。将当前数组中的每个视图控制器设置为每个导航控制器的根视图控制器。

编辑:

UIViewController *disController1 = [[DisController1 alloc]initWithNibName:@"DisController1" bundle:nil];
UIViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UIViewController *wishlistController = [[Wishlist alloc]initWithNibName:@"Wishlist" bundle:nil];
UIViewController *helpController = [[HelpController alloc]initWithNibName:@"HelpController" bundle:nil];
UIViewController *disController2 = [[DisController1 alloc]initWithNibName:@"DisController2" bundle:nil];


UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:disController1];

//etc. for each of the view controllers that you have allocated. 

NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
[viewControllersArray addObject:navController1];
[viewControllersArray addObject:navController2];
[viewControllersArray addObject:navController3];
[viewControllersArray addObject:navController4];
[viewControllersArray addObject:navController5];
于 2013-01-17T04:33:29.810 回答