Sallu Sallu - 2 years ago 60
Swift Question

Should I make separate UIViewController just because a single row is different in layout

I am a very basic SWIFT Xcode programmer. I make small apps.
For last 2 days, I am stuck at a very simple thing and I am sure with your guidance I can quickly make a decision.

I have a UIViewController class as well as an xib
In the layout I have 4 textfields

Now based on a user setting (in another frame user make a choice), I will either have to show 4 textfields ** OR ** 3 textfields and a UISwitch.

Long story short, if user select one option he should see UISwitch and 3 textfields or else 4 textfield. The labels's text also change.

To my limited knowledge, I will make another UIViewController, another XIB file and if user selection allows I will segue to the new UIViewController.

But all this looks so redundant. How do you smart people do this thing?

  • (Edit)
    I use size classes in my layout as well as constraints in the visual editor for positioning of elements on the layout. If I change things programmatically, which is one option, how will I manage the layout ?

Please advise.
Show me the right path please.

Answer Source
when user select first option based on action show or hide the text field or switches

like when user select first option only show three text field and one UIswitch hide fourth text field.and programatically change text field hint value and also set NSString Tag="first"
 so that when you want that value at the time of submit button you can apply if condition to tag and on that basis you can get your desired output on each selection
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download