title: Adding tableView with navigation controller to a view-based project - iPhone Programming
body: <p>I have a view based project with a set of buttons.</p>
  
  <p>When one of the buttons is pressed I would like a table view with a Navigation controller to be created.  I have this code in another project.</p>
  
  <p>My code is basically this tutorial with some minor changes (just the first 2 parts):
  <a href="http://www.xcode-tutorials.com/uitableview-%E2%80%93-1-creating-a-simple-table-view/" rel="nofollow">CODE</a></p>
  
  <p>Is there a way to import this code into my main project so that when the button is pressed the preceding code executes?</p>
  
  <p>EDIT:</p>
  
  <p>I use this method to allow me to change views:</p>
  
  <pre><code>- (void) displayView:(int)intNewView{
  
  NSLog(@"%i", intNewView);
  [currentView.view removeFromSuperview];
  [currentView release];
  
  switch (intNewView) {
      case 1:
          currentView = [[View1 alloc] init];
          break;
      case 2:
          currentView = [[View2 alloc] init];
          break;
      case 3:
          currentView = [[View3 alloc] init];
          break;
      case 4:
          currentView = [[View4 alloc] init];
          break;
      case 5:
          vc = [[RootViewController alloc] init];
          currentView = [[UINavigationController alloc] initWithRootViewController:vc];
          [self presentModalViewController: currentView animated:YES];
          break;
  }
  
  [UIView beginAnimations:nil context:nil];
  
  [UIView setAnimationDuration:0.5];
  
  [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft  forView:self.view cache:YES];
  
  
  [self.view addSubview:currentView.view];
  
  [UIView commitAnimations];
  
  }
  </code></pre>
  
  <p>RootViewController is the correct controller.  If I remove the 2 lines:</p>
  
  <pre><code>currentView = [[UINavigationController alloc] initWithRootViewController:vc];
          [self presentModalViewController: currentView animated:YES];
  </code></pre>
  
  <p>And replace vc with currentView in the rootview initialiser then the code works, and my table is displayed using my custom cells and successfully parses the xml and displays the correct data, but without a navigation controller.  However when I add the 2 lines above the table view doesnt work and I get an XML error code 5...Any ideas?</p>
  
  <p>Thanks,</p>
  
  <p>Jack</p>