Robert J. Clegg
Robert J. Clegg

Reputation: 7370

Reusing a UIViewController in storyboards?

I'm busy design a UI for an app that I am making. The UI will have a few UITextField boxes where the user fills in the info. Then, they would hit next and go to another screen for additional info that is related to the first screen.

Now I wanted to approach this like so:

In storyboard have the two or three screen with UITextField and other small UI stuff. However these three screens share the same viewController class as their "job" is the same job.

Would this be a good way to go about it?

I just don't want three viewController classes for the same "job" that seems messy to me.

Upvotes: 0

Views: 953

Answers (3)

CoolMonster
CoolMonster

Reputation: 2267

Create UIView with Xib for various form. Then when ever necessary create corresponding UIView and Add it as subview to ViewController main view with simple animation. When you don't need it simply remove or hide(When need in future) from the current ViewController.

Upvotes: 1

Aravind G S
Aravind G S

Reputation: 392

just call

[self viewWillAppear:YES];

and in your

- (void) viewWillAppear:(BOOL)animated
{

    //set the views according to your need for each case
}

Upvotes: 1

Ethan Fang
Ethan Fang

Reputation: 1269

Not sure my solution fits you. You can create three controllers in storyboard but one controller in your code. Then you set the class type of the three controllers to the same controller of your code.

However I have never done this before. I will have three controllers if I were you.

Upvotes: 1

Related Questions