4

I'm learning this right now so the questions might be a little juvenile. Here's what I'm trying to do. I have the first view come up with a cell of the table populated statically, when you select one of the cells it will pull up a form to input data.

Now, I've been reading the documentation about navigation buttons and navigation in general and it seems that I need two separate viewControllers. One for the basic app and another for the new page being brought forward when the cell is picked. Is this correct?

Sorry, this might be a little bit basic but I'm not sure what to do here. Thanks.

ckc123inDC
  • 125
  • 1
  • 2
  • 7

3 Answers3

3

That is correct. You would have two view controllers: a "root" view controller that is the top-most view, and the second view controller that contains the editing form.

The second view controller would get pushed onto the navigation stack when you tap a cell.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
2

Yes, you need two view controllers.

Check out lesson 7 from Stanfords CS193P iPhone Application Programming course. It is available online. Both slides and the lecture through iTunes U.

CS193P iPhone Application Programming

I really enjoyed watching the course!

Niels Castle
  • 8,039
  • 35
  • 56
2

Basically you need to create a second UIViewController subclass, this viewcontroller needs to be attached to your main window when switching views.

-(IBAction) SwitchView:(id)sender
{
MySubViewController *subViewController = [[MySubViewController] alloc]
                                         initWithNibName:@"SubView" bundle:nil];
self.view insertSubView:subViewController.view atIndex:0];
[subViewController release];
}
Mez
  • 2,817
  • 4
  • 27
  • 29
  • Is there a way to, at a later date, change the rootviewcontroler to a uiviewcontroleer subclass? Say I decide I should have another window view in front of the table view/RootViewController. How would you do that? – ckc123inDC Nov 02 '09 at 19:21
  • The root view controller that you have is already a `UIViewController` subclass. If you want another view in "front" of the root view controller, you can just add that view as a subview of the root view controller and place it on top of all the other subviews. – Alex Reynolds Nov 02 '09 at 19:31
  • 2
    It is never really good to manually manage view hierarchy by adding the viewController view to the current view. If you do this way, you viewController will never have it's default methods called. – Ludovic Landry Oct 03 '11 at 15:36