Reputation: 13297
I want to build an application with one main view that will be on-screen most of the time. Part of the view is constant and displays main controls. However, there is a special sub-view that depends on the state of the app. The state of the app is presented with a special 'state object'. There can be only one 'state object' active at once, but they can have very different logic and should be presented with different user interfaces (within this special sub-view).
Obviously, I can handle it in the ViewController of the main view by analyzing the type of the current state object. I can create a biiiig switch with a lot of code specific to every possible class that the state object can have, and add some code there every time I add a new state object subclass... But this doesn't sound like a good architecture to me. I want the state objects, or the different ViewControllers specific to them to take control of this special view instead. Unfortunately, I feel a bit lost in views, viewControllers & delegates & don't understand how exactly can I achieve this.
Upvotes: 0
Views: 102
Reputation: 3805
Each different subview type is a separate view controller with its own associated view.
Upvotes: 0
Reputation: 5028
It is important to remember that the View Controller and the UI (XIB) are two different things. You can implement a controller to handle the logic of your various subviews and then bind that instance of your controller to a different UI based on context using init with NibName...
This allows you to write your controlling logic once and spawn as many different and varied UI experiences as you need. The XIBs would all need to tie back to a centralized set of IBOutlets and you will be all set. Chances are there are large areas of similarity ion the sub-views given they still live in the overall context of your app. This strategy of one view controller to potentially many XIBs helps simplify development along those lines.
Good Luck.
Upvotes: 0
Reputation: 1783
If you need to handle a lot of logic stuff in those slate views, you may want to make them as view controllers, then add to main view controller when you need them using container approach as shown in Session 102 - Implementing UIViewController Containment. Basically like this:
[self addChildViewController:childViewController];
[childViewController didMoveToParentViewController:self];
[self.view addSubView:childViewController.view];
You can even use this method for transition animation: transitionFromViewController: toViewController: duration: options: animations: completion:
Upvotes: 1