Translate

2012年7月16日 星期一

UITabBarController UINavigationController

今天寫app的時候
忽然發現畫面上的UITabBarController的tabbar都要一直存在著
所以上網查了一下該如何呈現
原來把原來的寫法加上UINavigationController就可以了

原本寫法

UITabBarController *tabBarRootController = [[UITabBarController alloc] init]; tabBarRootController.delegate = self; AboutTableViewController *firstViewController = [[AboutTableViewController alloc] initWithNibName:@"AboutTableViewController" bundle:nil]; TravelTableViewController *secondViewController = [[TravelTableViewController alloc] initWithNibName:@"TravelTableViewController" bundle:nil]; AboutTableViewController *thirdViewController = [[AboutTableViewController alloc] initWithNibName:@"AboutTableViewController" bundle:nil]; AboutTableViewController *fourthViewController = [[AboutTableViewController alloc] initWithNibName:@"AboutTableViewController" bundle:nil]; AboutTableViewController *fifthViewController = [[AboutTableViewController alloc] initWithNibName:@"AboutTableViewController" bundle:nil]; tabBarRootController.viewControllers = [NSArray arrayWithObjects:firstViewController,secondViewController,thirdViewController,fourthViewController,fifthViewController,nil]; [self.navigationController pushViewController:tabBarRootController animated:YES];

後來改成

UITabBarController *tabBarRootController = [[UITabBarController alloc] init]; tabBarRootController.delegate = self; AboutTableViewController *firstViewController = [[AboutTableViewController alloc] initWithNibName:@"AboutTableViewController" bundle:nil]; UINavigationController* firstnavController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; TravelTableViewController *secondViewController = [[TravelTableViewController alloc] initWithNibName:@"TravelTableViewController" bundle:nil]; UINavigationController* secnavController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; AboutTableViewController *thirdViewController = [[AboutTableViewController alloc] initWithNibName:@"AboutTableViewController" bundle:nil]; UINavigationController* thirdnavController = [[UINavigationController alloc] initWithRootViewController:thirdViewController]; AboutTableViewController *fourthViewController = [[AboutTableViewController alloc] initWithNibName:@"AboutTableViewController" bundle:nil]; UINavigationController* fourthnavController = [[UINavigationController alloc] initWithRootViewController:fourthViewController]; AboutTableViewController *fifthViewController = [[AboutTableViewController alloc] initWithNibName:@"AboutTableViewController" bundle:nil]; UINavigationController* fifthnavController = [[UINavigationController alloc] initWithRootViewController:fifthViewController]; tabBarRootController.viewControllers = [NSArray arrayWithObjects:firstnavController,secnavController,thirdnavController,fourthnavController,fifthnavController,nil]; [self.navigationController pushViewController:tabBarRootController animated:YES];

沒有留言:

張貼留言