title: IOS Display different views from dynamically created nav bar
body: <p>I need to dynamically add a UIViewController that contains a nav bar with multiple buttons. When one of the buttons is pressed i need to swap the displayed view for another, while keeping the nav bar. </p>
  
  <pre><code>CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; 
  
  ViewControllerOne* viewOne = [[ViewControllerOne alloc] init];
  [viewOne.view setFrame:appFrame];  
  
  UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44.01)]; 
  NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
  
  UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(back:)];
  [buttons addObject:bi];
  [bi release];
  
  bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
  [buttons addObject:bi];
  [bi release];
  
  bi = [[UIBarButtonItem alloc] initWithTitle:@"Two" style:UIBarButtonItemStyleBordered target:self action:@selector(showTwo:)];
  [buttons addObject:bi];
  [bi release];
  
  [tools setItems:buttons animated:NO];
  [buttons release];
  viewOne.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
  [tools release];
  
  m_navViewController = [[UINavigationController alloc] initWithRootViewController:viewOne];
  [m_navViewController.view setFrame: appFrame ];
  [self addSubview: m_navViewController.view];
  </code></pre>
  
  <p>Now when someone presses the Two button i would like to remove viewOne and add a ViewControllerTwo object</p>
  
  <pre><code> - (void) showTwo:(id)sender{
      ViewControllerTwo* viewTwo = [[ViewControllerOne alloc] init];
      [viewOne.view setFrame:[[UIScreen mainScreen] applicationFrame]]; 
  
      // remove viewOne from m_navViewController and add viewTwo
  }
  </code></pre>
  
  <p>In other words i want to show different views by pressing one of items in the nav bar but keep the same nav bar for all views.</p>
  
  <p>Please note the nav bar will actually hold five buttons. I have  simplified it for explanation purposes. </p>
  
  <p>Thanks in advance.</p>