简体   繁体   中英

Running performSegueWithIdentifier on navigation view controller login screen transitions through two screens

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM