title: iPhone app with tab bar and navigation bar as peers
body: <p>I'm trying to write an application that uses a navigation bar and tab bar in what (I'm gathering) is an unusual manner.</p>
  
  <p>Basically, I've got several "pages" ("home", "settings", etc) that each have their own tab. I'd also like to have it so that the "home" page is the root view of the navigation bar, and the other pages are the second-level views of the navigation bar. That is, I should be able to navigate to any page by clicking the appropriate tab bar item, and should be able to navigate to the home page from any other page by clicking the navigation bar's back button.</p>
  
  <p>Currently, I have a UINavigationBar (through a UINavigationController) and a UITabBar (through a UITabController) as children of a UIView. The various pages' view controllers are set as the tab controller's <code>viewControllers</code> property, and the home page's controller is also set as the navigation controller's root view. Each page view's tag is set to its index in the tab control. I have the following logic in the tab controller's <code>didSelectViewController</code> delegate method:</p>
  
  <pre><code>- (void) tabBarController:(UITabBarController*) tabBarController
      didSelectViewController:(UIViewController*) viewController
  {
      if ([navController.viewControllers count] &gt; 1)
          [navController popViewControllerAnimated:NO];
  
      [navController pushViewController:viewController animated:YES];
  }
  </code></pre>
  
  <p>Also, in the navigation controller's <code>didShowViewController</code> delegate method, I have the following code:</p>
  
  <pre><code>- (void) navigationController:(UINavigationController *) navigationController
      didShowViewController:(UIViewController *)viewController
      animated:(BOOL)animated
  {
      tabController.selectedIndex = viewController.view.tag;
  }
  </code></pre>
  
  <p>The problem that's occurring is that when I run this, the navigation bar, tab bar and home page all display ok, but the tab bar will not respond to input - I cannot select a different tab.</p>
  
  <p>I gather it's more usual to have the tab bar as the child of the navigation control, or vice versa. This doesn't seem to fit my approach, because I don't want to have to individually create the subordinate control each time a change occurs in the parent control - eg: recreate tab bar each time the navigation bar changes.</p>
  
  <p>Does anyone have suggestions as to what's wrong and how to fix it? I'm probably missing something obvious, but whatever it is I can't seem to find it. Thanks!</p>
  
  <p>EDIT: I'm guessing it has something to do with both controller's trying to have ownership of the page controller, but I can't for the life of me figure out a way around it.</p>