Reputation: 91
Im trying to write a function that will take me from on storyboard to the next using a button. I am new to iOS app dev and Swift. I have a button with this IBAction but im not sure how to connect pages. Meaning going to the next page using a button. thanks.
@IBAction internal func nextBtn(_ sender: Any)
}
Upvotes: 1
Views: 630
Reputation: 527
Drag from the View in storyboard we’re you have the brutton on , crt drag from the yellow dot on the top of the view, to next view you want to navigate to. Give it a name in and put this in your button function.
// segueName is your name on segue
performSegue(withIdentifier: "segueName", sender: self)
Difference between drag it straight from the button or the view controller is that you can’t have any if statement if you drag it from the button.
Exp you only want to execute segue if user did something and the pressed the button you need to disable the button. Otherwise it will always be executed.
But if you use a performsegue in the button action you could easy make a statement and and execute the segue.
Upvotes: 1
Reputation: 3323
No need to write any code for this, it can all be done in Interface Builder. Create a storyboard reference in IB, and control-drag from the “next” button to the storyboard reference. Done.
There is a nice tutorial with pictures here: https://medium.com/@wilson.balderrama/how-to-segue-between-storyboards-86c582f976f7
Upvotes: 0