Reputation: 1022
I am working on an Exercise App, where UI depends on the type of Exercise. Some exercises have the question as text and answer as text. Some exercises have the question as text and answer as images. One more variation is image and text in question and image in the answer. I create a question object based on the values I get from API for a particular Exercise. That object has many fields as optional. For example, the image is optional. Now the challenge I am facing is what is the best way to handle such dynamic UI. In plain English, if it has the image, show the imageView and if it doesn't have the image, don't show the imageView and adjust other UI elements accordingly.
Upvotes: 0
Views: 227
Reputation: 16246
You can have one UIViewController subclass, and many different storyboards each with a different layout and subviews.
Each storyboard has the view controller's class set to your custom class in the identity inspector.
Your view controller has outlets for all possible subviews, and each storyboard connects its subviews to the outlets that are relevant to it.
When you need to present a particular variation of the string, you instantiate your view controller from a case-specific storyboard (programmatically or using segues and storyboard references).
If you only need to disable one particular subview in one case, you can do one of the following:
false
. It will stay in place, and occupy the same area, but invisible.removeFromSuperview()
. Be careful if other, remaining subviews rely on constraints against the removed subview for their layout, though.Upvotes: 1