laufeyson
laufeyson

Reputation: 9

Xcode showing different view controllers based on a condition

I am new to Xcode/swift and my problem right now would be showing 2 different view controllers. For example, when I choose negative from a pickerview and press a next button, another form would come up. However, if I choose positive, when I press the next button it will show a successfully booked view controller. How can I do this? Should I use let else ? In my storyboard, do I create 2 view controllers with different segues as well?

Thank you!

Upvotes: 0

Views: 38

Answers (1)

zdtorok
zdtorok

Reputation: 732

You should check if the chosen one is positive or not and then perform the correct segue. It all just goes down to which segue you will perform.

if (isNegativeChosen) {
    performSegue(withIdentifier: "showView1", sender: self)
} else {
    performSegue(withIdentifier: "showView2", sender: self)
}

In storyboard you have to set up the two segues going out from this view controller to the two new ones and have 'showView1' and 'showView2' as their names set accordingly.

Upvotes: 1

Related Questions