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
Naomi Touchet
11,300 PointsHow do I create a multi-page application in Swift in XCode?
I'm trying to create a multi-page application for iOS using Swift in XCode. I started with the Fun Facts project from the track and I'm hoping to create a home page with a couple buttons on it where you can click one of the buttons to go to the Fun Facts page and then click another button to go to another activity. How do I create new pages and link them to each other?
2 Answers
Nick Sint
4,208 PointsTo achieve this, you can do this 2 ways depending on what you want.
Method 1: Using interface builder
Simply go to your storyboard file, drag and drop as many view controllers as you want (I'm assuming you want to have 3 in total since your going to have essentially a "main menu", "funfacts" and "other"). Once done, create two buttons in your "main menu" and ctrl+drag them to each individually to the view controller you desire (i.e. with button 1, crtl+drag onto "funfact" view controller and with button 2 ctrl+drag onto "other" view controller).
Method 2: Programatically call view controller
For this, you will use the self.performSegueWithIdentifier. The difference here is that when you do the ctrl+drag, you simply have to ctrl+drag the view controller not the button. For more info, refer to:
Naomi Touchet
11,300 Pointsthanks! that was helpful.