Ben
Ben

Reputation: 317

How to set if else statement for ViewController segues?

I apologize if this is a simple question, but I am new to learning Swift. I am currently developing a simple app where you can rate certain categories of your day (e.g. mood, social, sleep). The user has the ability to enable and disable certain categories. When the user goes to log a new day, they enter a Navigation Controller where they will select a rating for a given category and then tap on the arrow at the upper-right hand corner to advance to the next category until each category has been rated. (see image below)

(see wireframe image here)

Is there a way for me to program which ViewController follows after each preceding ViewController? For example, if the user disables the mood category, the user should not be presented to rate their mood category when logging a new day.

Thank you to everyone in advance!

Upvotes: 0

Views: 85

Answers (2)

Petr Kramolis
Petr Kramolis

Reputation: 255

You can make one "main" storyboard and add seques to all rating controllers. Then add logic to the "main" controller that would call different sequey each day with out animation.

Upvotes: 1

Krumelur
Krumelur

Reputation: 33048

This is not possible directly in the storyboard. You can however use a hybrid approach: design the individual controllers but trigger the navigation from within your code.

To create an instance of a VC from a StoryBoard use

func instantiateViewController(withIdentifier identifier: String) -> UIViewController.

You will have to assign a storyboard ID to your controllers.

Further documentation over at Apple.

Upvotes: 2

Related Questions