Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Michael Kantor
Michael Kantor
2,183 Points

How to switch views programmatically in Swift?

I'm also a bit confused on what a "Segue" is and I've seen it in a few answers related to this question, but simply put, how do I switch views based on say, a Users Session..

if(loggedOut = true) {  show sign in view }else {do nothing}

3 Answers

self.performSegueWithIdentifier("signInView", sender: self)

Michael Kantor
Michael Kantor
2,183 Points

the view name is the storyboard id?

signInView is the name of the segway you make in the storyboard.

Michael Kantor
Michael Kantor
2,183 Points

And its suffixed with View ?

So to start answering your question, you should have a segway between two view controllers, a segway is a link between two controllers. To create go to your storyboard file, press the ctrl button on your keyboard, click on the view related to the code before, hold the click and select the target view controller.

Michael Kantor
Michael Kantor
2,183 Points

How would I programmatically switch to one of the tabs?

with performSegueWithIdentifier

Michael Kantor
Michael Kantor
2,183 Points

Could you show me an example? I can't figure out how to access that..