views:

665

answers:

1

I'm a bit confused about how many controllers I need, and when I can load in UIViews into the same controller, versus having two controllers for two separate UIViews.

Here's my current situation. I have a simple app that takes in information on the beginning screen, and then based on the info from the user (via a UIPicker and a textfield), it displays a flip animation to a new view that is one of two choices: ViewA or ViewB.

Right now, I have a root controller GenController.view that gets loaded into the UIWindow after launch. Then in GenController, in the ViewDidLoad method, I create an instance of another controller GetInfoController, and insertSubview into self.view, which at this point, self is the original instance of GenController.

getInfoController takes in the information, does some logic on the user entries and then loads either an instance of ViewAController or ViewBController accordingly.

ViewAController and ViewBController are very similar, but just have a UIView that looks slightly different. The user interactions with the screen will be the same.

I feel like 1)GenController and GetInfoController should be the same, but I'm not sure how to integrate them. Do I load GetInfoController directly into the UIWindow? Do I need to do anything in ViewDidLoad then? 2)should I have one viewXController instead of one for ViewA and ViewB?... how do I load different UIViews into the one controller, based on the logic in GetInfo?

+3  A: 

It sounds like you'll want to use a UINavigationController. It maintains several UIViewControllers, and makes it easy to switch from one to another.

Generally, a single UIViewController maintains a single UIView. (Hence the 'view' property on the UIViewController class.)

In the first UIViewController, when you want to switch to the second UIViewController, you can do something like:

[self.navigationController pushViewController:secondViewController animated:YES];
craig