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.
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:
You can even use this method for transition animation:
transitionFromViewController: toViewController: duration: options: animations: completion: