我正在使用tabbar,当我导航到该控制器时,我的标签栏没有显示,
这是tabbar类的代码
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;
当我将此视图控制器推送到导航控制器时,当导航栏未隐藏时显示标签栏,当我隐藏导航栏并使用工具栏时,现在底部的标签栏未显示。
需要提前感谢快速回复。
答案 0 :(得分: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];
希望这有帮助。
答案 1 :(得分:0)
尝试使用此代码创建Custom tabbarController
。在这里,我创造了两个而且你可以轻松地制作它。
了解更多了解请查看我的回答:iOS code optimization
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];