斯威夫特 - Segue双击

时间:2015-12-05 15:56:58

标签: ios xcode swift

我有一个检查表单输入的函数,然后如果基于布尔变量有效,它将启动performSegue以转换到下一个阶段。

我有3个用户注册视图: 1-基本细节 2-用户名 3-帐户验证

当我点击按钮时,它会从基本详细信息转到用户名视图...然后立即转到帐户验证。用户名ViewController中ViewDidLoad函数体内的print语句打印到控制台两次(奇怪!)。

以下是我的代码正文:

@IBAction func proceedPressed(sender: AnyObject) {
        print("Proceed Pressed");
        if nameTextField.text != "" || emailTextField.text != "" || passwordTextField.text != "" || mobileTextField.text != ""
        {
             /*Check Formatting of Fields and Rules*/
            let validationResult = true
            /*Store in userObject for further processing*/
            if(validationResult == true)
            {
                //updateing objects
                self.performSegueWithIdentifier("selectUsernameSegue", sender: sender);
            }


        }else{
            /*Display validation error on screen*/
            print("Some Fields are Empty!");
        }

    }

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        if (segue.identifier == "selectUsernameSegue") {
            // pass data to next view
            let destinationVC = segue.destinationViewController as! UsernameViewController
            destinationVC.userObject = self.userObject;

        }
    }

和我在两个视图(1和2)之间的segue称为selectUsernameSegue。为什么它会显示第二个视图控制器然后直接移动到第三个?

谢谢,

UsernameViewController正文:

class UsernameViewController: UIViewController {

    var userObject = UserClass();

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        print("Email: " + userObject.email!);
    }

1 个答案:

答案 0 :(得分:2)

您已从按钮连接了您的segue。

按下按钮时会立即触发segue,第二次拨打performSegueWithIdentifier时会触发。相反,如果您想使用viewController触发它,则应该从viewController顶部的performSegueWithIdentifier图标连接segue:

wiring segue