Tab bar controller inside a navigation controller, or sharing a navigation root view

Posted by Daniel Dickison on Stack Overflow See other posts from Stack Overflow or by Daniel Dickison
Published on 2009-02-23T07:10:26Z Indexed on 2010/04/25 2:03 UTC
Read the original article Hit count: 639

I'm trying to implement a UI structured like in the Tweetie app, which behaves as so: the top-level view controller seems to be a navigation controller, whose root view is an "Accounts" table view. If you click on any account, it goes to the second level, which has a tab bar across the bottom. Each tab item shows a different list and lets you drill down further (the subsequent levels don't show the tab bar).

So, this seems like the implementation hierarchy is:

  • UINavigationController
    1. Accounts: UITableViewController
    2. UITabBarController
      1. Tweets: UITableViewController
        • Detail view of a tweet/user/etc
      2. Replies: UITableViewController
      3. ...

This seems to work[^1], but appears to be unsupported according to the SDK documentation for -pushViewController:animated: (emphasis added):

viewController: The view controller that is pushed onto the stack. It cannot be an instance of tab bar controller.

I would like to avoid private APIs and the like, but I'm not sure why this usage is explicitly prohibited even when it seems to work fine. Anyone know the reason?

I've thought about putting the tab bar controller as the main controller, with each of the tabs containing separate navigation controllers. The problem with this is that each nav controller needs to share a single root view controller (namely the "Accounts" table in Tweetie) -- this doesn't seem to work: pushing the table controller to a second nav controller seems to remove it from the first. Not to mention all the book-keeping when selecting a different account would probably be a pain.

How should I implement this the Right Way?

[^1]: The tab bar controller needs to be subclassed so that the tab bar controller's navigation item at that level stays in sync with the selected tab's navigation item, and the individual tab's table controller's need to push their respective detail views to self.tabBarController.navigationController instead of self.navigationController.

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about iphone