1

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)

}

2 Answers 2

1

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.

2
  • No need for this, You name the segue and deal with conditions in the shouldPerformSegue method of the view controller
    – Dale
    Nov 17, 2018 at 22:37
  • It totalt depends what you doing but in general you shouldn’t drag straight from a button. Nov 18, 2018 at 7:29
0

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

1
  • It’s not the best idea. If you want to make a statement in case of you will still execute the segue. Nov 16, 2018 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.