尝试将变量传递给下一个视图控制器时出错

时间:2016-03-18 16:26:14

标签: ios swift

我的segue被称为“SegueAfterJoin”,它所使用的视图控制器称为SignUpViewController3 - 我已经确定了这一点。 Xcode说“使用未声明的类型SignUpViewController3”。

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "SegueAfterJoin") {
        var svc = segue.nextViewController as SignUpViewController3;

        svc.toPass = self.passwordtextfield.text
        svc.toPass = self.usernametextfield.text
        svc.toPass = self.emailtextfield.text


    }
}

2 个答案:

答案 0 :(得分:1)

以下是您应该使用的代码

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if (segue.identifier == "SegueAfterJoin") {
        var svc = segue.destinationViewController as! SignUpViewController3;

        svc.toPass = self.passwordtextfield.text
        svc.toPass = self.usernametextfield.text
        svc.toPass = self.emailtextfield.text


    }
}

答案 1 :(得分:1)

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "SegueAfterJoin") {
        if let svc = segue.destinationViewController as? SignUpViewController3 {
            svc.toPass = self.passwordtextfield.text
            svc.toPass = self.usernametextfield.text
            svc.toPass = self.emailtextfield.text
        }
    }
}

确保SignUpViewController3源文件存在于您的项目中并包含在目标中。