目标:TabBar下的每一个view都有自己的NavigationBar
代码:
interface buider里的方法:
将Navigation Controller作为TabBar Controller的子视图控制器。
每个TabBar的子视图用一个Navigation Controller。
Navigation Controller的子视图用来实现要显示的View:将Custom Class和Nib Name改成自己新建的ViewController,在那里写自己实现的代码。
原理:TabBar的ViewControllers属性可以添加各种View Controller,包括Navigation Controller。
Navigation Controller的子视图指定为想要实现的view Controller。
代码:
tabBarController = [[UITabBarController alloc] init];
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
tabBarController.viewControllers = [NSArray arrayWithObjects:firstNavigationController,secondNavigationController,nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
interface buider里的方法:
将Navigation Controller作为TabBar Controller的子视图控制器。
每个TabBar的子视图用一个Navigation Controller。
Navigation Controller的子视图用来实现要显示的View:将Custom Class和Nib Name改成自己新建的ViewController,在那里写自己实现的代码。
原理:TabBar的ViewControllers属性可以添加各种View Controller,包括Navigation Controller。
Navigation Controller的子视图指定为想要实现的view Controller。