Search code examples
swiftstoryboardsegue

How to control storyboard segue


I created a segue using storyboard which links the login button to the view which is supposed to be opened when a user logs in. My problem is i have to do a network call and show a loader when a user clicks this button. Only when login is successful thats when i want to go to the next view else it should show an alert message saying unable to login.

The problem is i cant seem to stop the storyboard sugue for me to perform necessary calls before going to the next view.

This is my code :

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "loginSuccessSugue"{
          let spinner = self.showLoader(view: self.view)
          self.makeApiCall()
    }
}

Solution

  • use func performSegue(withIdentifier identifier: "loginSuccessSugue", sender: self) after completion of your login calls.