0

我正在使用标签栏,当我导航到该控制器时,我的标签栏没有显示,

这是标签栏类的代码

UIViewController * myTruckDept= [[NYTTruckDeparture alloc]initWithSiteName:self.siteNam andSiteDate:self.date];
UIViewController * myEditionStates = [[NYTEditionStats alloc] initWithSiteName:self.siteName andSiteDate:self.date];
UIViewController * myPagingData = [[NYTPagingData alloc] initWithSiteName:self.siteName andSiteDate:self.date];
UIViewController * myDownTimeLog = [[NYTDowntimeLog alloc] initWithSiteName:self.siteName andSiteDate:self.date];
UIViewController * myComments = [[NYTComments alloc] initWithSiteName:self.siteName andSiteDate:self.date];

NSArray *array = [[NSArray alloc] initWithObjects:myTruckDept, myEditionStates, myPagingData, myDownTimeLog, myComments, nil];

self.viewControllersArray = array;
[self.view addSubview:myTruckDept.view];
self.selectedViewController = myTruckDept;
self.myTabBar.selectedItem=self.myTruckDeptTabBarItem;

当我将此视图控制器推送到导航控制器时,导航栏未隐藏时会显示标签栏,当我隐藏导航栏并使用工具栏时,底部的标签栏不会显示。

需要快速回复提前谢谢。

4

2 回答 2

0

//定义UIViewControllers

UIViewController * myTruckDept= [[NYTTruckDeparture alloc]initWithSiteName:self.siteNam andSiteDate:self.date];
UIViewController * myEditionStates = [[NYTEditionStats alloc] initWithSiteName:self.siteName andSiteDate:self.date];
UIViewController * myPagingData = [[NYTPagingData alloc] initWithSiteName:self.siteName andSiteDate:self.date];
UIViewController * myDownTimeLog = [[NYTDowntimeLog alloc] initWithSiteName:self.siteName andSiteDate:self.date];
UIViewController * myComments = [[NYTComments alloc] initWithSiteName:self.siteName andSiteDate:self.date];

//在 UINavigation 控制器中添加视图

UINavigationController * myTruckDeptNavC = [[UINavigationController alloc] initWithRootViewController: myTruckDept];
UINavigationController *topyummsNavC = [[UINavigationController alloc] initWithRootViewController: myEditionStates];
UINavigationController *myEditionStatesNavC = [[UINavigationController alloc] initWithRootViewController: myPagingData];
UINavigationController * myDownTimeLogNavC = [[UINavigationController alloc] initWithRootViewController: myDownTimeLog];
UINavigationController * myCommentsNavC = [[UINavigationController alloc] initWithRootViewController:myComments];

//隐藏导航栏

myTruckDeptNavC.navigationBar.hidden = YES;
topyummsNavC .navigationBar.hidden = YES;
myEditionStatesNavC.navigationBar.hidden = YES;
myDownTimeLogNavC .navigationBar.hidden = YES;
myComments NavC.navigationBar.hidden = YES;

//初始化标签栏并设置控制器

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects: myTruckDeptNavC, topyummsNavC, myEditionStatesNavC ,myDownTimeLogNavC , myCommentsNavC, nil];
self.tabBarController.delegate = self;

//呈现UITable Bar

[self.window.rootViewController presentModalViewController:self.tabBarController animated:animated];

希望这对您有帮助。

于 2013-01-03T11:07:06.557 回答
0

试试这个创建代码Custom tabbarController。在这里我为两个创建了你可以轻松地将它变成 4 个。

更多了解查看我的答案: iOS 代码优化

tabBar_Controller = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray =[[NSMutableArray alloc]initWithCapacity:2];


firstViewController = [[FirstViewController alloc] initWithSiteName:self.siteNam andSiteDate:self.date];
nav = [[UINavigationController alloc] initWithRootViewController:firstViewController];
nav.tabBarItem.title = @"item1";
nav.navigationBar.barStyle = UIBarStyleBlack;
nav.navigationBar.hidden = YES;
[localControllersArray addObject:nav];
[self setNav:nil];

secondViewController = [[SecondViewController alloc] initWithSiteName:self.siteNam andSiteDate:self.date];
nav = [[UINavigationController alloc]initWithRootViewController:secondViewController];
nav.navigationBar.hidden = YES;
nav.tabBarItem.title = @"item2";
[localControllersArray addObject:nav];
[self setNav:nil];

tabBar_Controller.viewControllers = localControllersArray;
tabBar_Controller.delegate = self;
tabBar_Controller.selectedIndex = 0;
[self.window addSubview:tabBar_Controller.view];
于 2013-01-03T11:08:11.863 回答