简体   繁体   English

在导航视图控制器登录屏幕上运行performSegueWithIdentifier会在两个屏幕之间切换

[英]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. 我已经在Xcode 7 beta 4中创建了一个故事板,并且正在使用Parse.com来存储我的数据。 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. 我只是想让segue将用户带到下一个屏幕...我不确定为什么它会在两个屏幕之间切换。

Here is my code for the "Login" button Action in LoginViewController.swift: 这是我的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; 编辑:而且,这在控制台中显示:pushViewController:animated:在现有过渡或演示发生时调用; 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. 您的问题似乎是您从按钮到新的视图控制器设置了segue,并从代码中调用了segue。 To resolve this issue delete the segues in storyboard. 若要解决此问题,请删除情节提要中的segue。 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. 然后重新创建segue,但是这次从视图控制器转移到另一个视图控制器-给新的segue与以前相同的标识符,这应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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