Search code examples
iosiphoneswiftibaction

Making a segue through button action


I am trying to make a login in screen where when you press login it will check the username and password then if it is all good it will segue to the next view.

I have 1 view controller with 2 buttons just to test that I can successfully segue with a button action to another view controller. 1 button is my attempt to programmatically link the two view controllers and the other button is linked by a modal and it successfully switches between the views.

for the first button my code is,

    @IBAction func testButton(sender: UIButton) {
        performSegueWithIdentifier("nextView", sender: self)
    }

for the storyboardID of the view controller to be switched to it is indeed 'nextView'

I get an error, 'NSInvalidArgumentException', reason: 'Receiver has no segue with identifier 'nextView'

I have cleaned up the code and also tried removing the app from the simulator.

Any suggestion on what the issue may be? Or is there a better way to make a login screen?


Solution

  • In order to perform segue on button tap with custom logic, select controller one (not button) control drag and drop on controller two. chose the segue and give an identifier value in storyboard. Then when you call performSegueWithIdentifier, it will work.