iPhone - Combining a Tab Bar with multiple navigation bars
I am trying to build an iPhone application that has a Tab bar as the root controller and several navigation bars. My doubt is, shall I create one NavigationBarController class for each navigation bar that I want to put in the application? Or is it possible to create only a single navigation controller that manages all the navigation bar controllers that exist in the application?
In the case that multiple navigation controllers exist in the application, can I use the "self" to access the correct navigation controller that pushes/pops the view? Or should I use the delegate of the Application delegate to access each navigation bar controllers?
(I 开发者_StackOverflow中文版am assuming that all navigation bar controllers are declared in the application delegate, is this approach correct or is there a more elegant approach?)
Thanks a lot in advance
The common way to achieve this is to create a Tab Bar application and then change each item in the tab bar to be a UINavigationController. If you do this, you can definitely use self to access the navigationController - specifically you can use self.navigationController
.
Watch out for possible leak in this part of the above code:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
You could use this instead:
UIBarButtonItem* rightButtonBar = [[UIBarButtonItem alloc] initWithCustomView:tools];
self.navigationItem.rightBarButtonItem = rightButtonBar;
[rightButtonBar release];
;) ... or use autorelease
Insert a unique UINavigationController
for each tab.
You can't have a single controller manage across multiple tabs, since a navigation controller can only have a single linear stack of view controllers. Each tab should have it's own navigation controller with a different root controller in each one.
The common way to achieve this is to create a Tab Bar application and then change each item in the tab bar to be a UINavigationController.
This is THE way of achieving this. I have loaded 5 navigation controllers into a tab bar controllor. The key tip is to plan the navigations of the App, as every navController should take place where a new navigation tree starts.
精彩评论