I have a simple NavigationController based app. The main window shows a TableView and selecting an item loads a sub-view. I used Interface Builder for UI views.
Now I want to add a TabBar to the app. Where do I put it? Do I need a TabBarController? Should it go in the MainWindow.xib, or RootViewController.xib?
How do I tie it together with my NavigationController?
The definitive answer to this question is presented in the iPhone SDK documentation in the View Controller Programming Guide for iPhone.
View Controller Programming Guide: Combining View Controllers
This link goes straight to the section and includes a discussion of the correct ways to create navigation and tab bar-based interfaces.
I do this in a couple of my apps. The trick to adding a tab bar to a navigationController based app is to NOT use a TabBarController. Add a Tab Bar to the view, make the view controller for that view a TabBarDelegate, and respond to user selections on the tab bar in the code of the view controller.
I use Tab Bars to add additional views to the Tab Bar's view as sub-views, to reload a table view with different datasets, to reload a UIPickerView, etc.
Take a look at the UICatalog sample code. It has lots of great stuff in it, including the transition from one view to the next.
In your case, you need to use the UITableView delegate method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
In that method, you'll create and display your tab view controller. This could be a custom controller with an associated Nib, or you could create the whole thing in code depending on your circumstance.
It's a better idea to have a navigation bar embedded in a tabbed application whenever possible. Doing it the other way creates some complications, is difficult when done with IB and leads to a lot of trouble.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With