James Skidmore
James Skidmore

Reputation: 50338

Is having all views linked to one view controller a bad practice?

For my application, I have one UIViewController and about 8 UIViews. The views are all properties of the view controller, linked via the Interface Builder (IBOutlet). So when the view controller loads, all of the views are also loaded, and I have built-in methods to switch back and forth between the different views.

Is it bad to have them all linked to one view controller -- should each view have its own view controller? Because they're all linked to one, I'm assuming they're all in memory at the same time and are never released because the view controller itself is never released.

What is the standard practice for this?

Upvotes: 1

Views: 237

Answers (1)

John Calsbeek
John Calsbeek

Reputation: 36547

If you have a bunch of views that will always be on-screen at the same time, then they should be controlled by one UIViewController.

If you have a bunch of views that will alternate between completely controlling the screen, then each view should have its own UIViewController.

If you have a single view that's always on-screen that delegates part of the screen to another view that can change, then you should have a UIViewController to manage the main view as well as one UIViewController per subview.

(Any time you have a view that can sometimes be on-screen and sometimes be off-screen, you should probably be using a UIViewController to manage its lifespan.)

Upvotes: 4

Related Questions