Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

MVC UIViewController vs UIView advice

I have an app that I originally built using 4 separate UIViewControllers so that I could have my AppDelegate call the appropriate view controller for the specific layout and view configuration. It seemed reasonable at the time.


Now, I want the user to be able to change the layout while running the app, and it doesn't seem to make sense to dismiss the entire view controller to restart the app from the AppDelegate level.


So, I think I should split the current view controller up into parts, with the base viewController having all the common elements, and then have the variable layouts (which each have a bunch of buttons) as separate UIViews which I just read from a nib file so only one layout is in memory at a time.


I separated the UIView elements into separate .xib files, but...

The only problem with that is there doesn't seem to be an way to simply read in a UIView from a nib file to add them to the existing view controller.


For MVC, it was my understanding that you only have one VC active at a time, so using a separate viewController to read in the appropriate button layout for only one small section of the screen was not appropriate.


Am I understanding that properly, or is it perfectly fine to have one VC controlling the top and bottom of the screen, a 2nd VC to handle the button layout view on the left side of the screen and a 3rd VC to handle the text display with clipping of the view to show only a portion allowing the main background (controlled by the first VC) to show through?


Or, if only one can be active, how should I manage the individual views?


Once this is re-done, I plan to add views for the iPad, and just have to manage the views that are different between the platforms, so whatever mechanism I choose should als work for universal apps.


Thanks!

Posted on Mar 18, 2012 5:23 AM

Reply
1 reply

Mar 18, 2012 2:52 PM in response to reststop

Well, I've done some more research since I posted the question, and loadNibNamed:owner:options: seems like one method to bring in the individual UIView objects as I started to do early in this update. (Instead of

initWithNibName:bundle: )

The examples in the Resource Programming Guide are a little sparce in this area.


I presume that once loaded from the nib file, I still need to add the view as a subView.



Alternatively, would it make the most sense to create my main view nib file including the default view with the button layouts in the default configuration, and then if/when the user selects a different layout, replace the current view with one that I load from the appropriate "alternative" nib file, freeing up the previous UIView object?


In this instance, the initial layout view will already be part of the subview structure added with the UIViewController, and I would simply be replacing the existing UIView object with a new one from my alternate nib file.


Right?

MVC UIViewController vs UIView advice

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.