我是iOS的新手。我想要的是,当用户成功注册时,应出现下一个视图控制器。我用于此目的的是prepareForSegue。用户已成功登录。调试显示,prepareForSegue也被调用,但它没有显示下一个屏幕。我也想发送我的用户"与segue一起变量。这是我的代码。
@IBAction func signUpTapped(_ sender: AnyObject!) {
let password = "password"
phone?.name = "phone_number"
phone?.value = "######"
email?.name = "email"
email?.value = "######"
attributes.append(phone!)
attributes.append(email!)
let userPool = appDelegate.userPool;
userPool?.signUp("user7", password: password, userAttributes: attributes, validationData: nil).continueWith { (task) -> Any? in
print("Successfully registered user: \(task.result!.user)");
print("error: \(task.error)");
self.user = task.result!.user
self.performSegue(withIdentifier: "toConfirmationCodeScreen", sender: self)
return nil
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "toConfirmationCodeScreen") {
let secondViewController = segue.destination as! ConfirmationCodeViewController
let user = sender as! AWSCognitoIdentityUser
secondViewController.user = self.user
}
}
非常感谢任何帮助。
P.S 我使用的是Swift 3,Xcode 8。
答案 0 :(得分:2)
答案 1 :(得分:0)
右键单击故事板中的按钮并拖动到下一个视图。不要在它们之间留下右键。你将获得Action Segue的选项 - 模型,显示,弹出,工作表。只需选择显示您已完成。
这样可以正常工作。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "toConfirmationCodeScreen") {
let secondViewController = segue.destination as! ConfirmationCodeViewController
let user = sender as! AWSCognitoIdentityUser
secondViewController.user = self.user
}
}