0
votes

I've created a storyboard in Xcode 7 beta 4, and I'm using Parse.com to store my data. My storyboard contains an initial screen with "Login" and "Signup" buttons which navigates the user (using modal segues) to their respective screens (the Login and Sign Up screens are two separate screens embedded in two separate navigation controllers). From the login screen, I have created a push segue to a new view controller (which is a post-sign in screen). There are no issues getting to the Sign Up and Login screens.

The issue is when a user successfully signs in via the Login screen. When I enter a valid users credentials and click 'Login', it segues to the next screen (with < "Login" on the navigation bar), and then immediately segues again to a non-existent screen (with < "Back" on the navigation bar). Does anyone know why this is happening? I simply want the segue to take the user to the next screen...I'm not sure why it's transitioning through two screens.

Here is my code for the "Login" button Action in LoginViewController.swift:

 @IBAction func loginButton(sender: AnyObject) {

    if emailAddressLogin.text == "" || emailAddressPassword.text == "" {

        displayAlert("Login Error", message: "Please enter a valid username and password")

    } else {

        activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
        activityIndicator.center = self.view.center
        activityIndicator.hidesWhenStopped = true
        activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
        view.addSubview(activityIndicator)
        activityIndicator.startAnimating()
        UIApplication.sharedApplication().beginIgnoringInteractionEvents()

        var errorMessage = "Please try again"

        PFUser.logInWithUsernameInBackground(emailAddressLogin.text!, password: emailAddressPassword.text!, block: { (user, error) -> Void in

            self.activityIndicator.stopAnimating()
            UIApplication.sharedApplication().endIgnoringInteractionEvents()

            if user != nil {

                self.performSegueWithIdentifier("login", sender: self)

            } else {

                if let errorString = error!.userInfo["error"] as? String {

                    errorMessage = errorString

                }

                self.displayAlert("Failed Sign Up", message: errorMessage)
            }

        })
    }
}

EDIT: Also, this is showing showing in the console: pushViewController:animated: called on while an existing transition or presentation is occurring; the navigation stack will not be updated.

1
Sounds like something is configured improperly in your storyboard. Perhaps an extra or duplicate segue, or reusing the segue identifier of the login transition on another segue accidentally? - Patrick Lynch
@PatrickLynch, I checked that numerous times and all of the segues in the storyboard have unique identifiers. If I remove self.performSegueWithIdentifier("login", sender: self), the problem gets resolved. However, the issue now is that the 'error' condition goes to the next screen and then displays the alert error 'Failed Sign Up'. I also get the following in the console: 'Presenting view controllers on detached view controllers is discouraged' - SB2015
Hmmm... do you have more than one IBAction connected to loginButton(_:), or any other reason why that function might be called twice? - Patrick Lynch

1 Answers

4
votes

Your issue appears to be that you set up a segue from the button to the new view controller AND call the segue from code. To resolve this issue delete the segues in storyboard. Then recreate the segues, but this time from the view controller to the other view controller - Give the new segues the same identifiers as before and this should solve the issue.