所以我正在尝试创建一个注册页面,但遇到了一些麻烦。我希望用户在点击注册之前必须填写所有信息。在他们点击注册按钮后,如果他们没有填写所有字段,他们会收到许多不同内容的 UIAlertView 错误。当我点击注册时,它会将用户带到下一页,然后显示 UIAlertView,我不希望这种情况发生。我不知道发生了什么。如果 UIAlertView 出现,如果他们没有填写用户名或电子邮件,我需要 UIAlertView 在他们单击按钮后显示,而不是转到下一页。我的代码中有一个 performSegue 方法,但它首先执行,而不是最后执行。有谁能够帮助我?我还将包括我的 Storyboard的屏幕截图。
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as? NSString
if fullname.isEmpty || email.isEmpty || username.isEmpty || password.isEmpty {
var emptyFields:UIAlertView = UIAlertView(title: "Plese try again", message: "It looks like you forgot to fill out all the fields. Please make sure all the fields are filled out so we can create an account for you.", delegate: self, cancelButtonTitle: "Try again")
emptyFields.show()
} else if error.code == 203 {
var takenEmail:UIAlertView = UIAlertView(title: "Please try again", message: "It looks like that email has already been taken, please try again.", delegate: self, cancelButtonTitle: "Try again")
} else if error.code == 202 {
var usernameTaken:UIAlertView = UIAlertView(title: "Please try again", message: "It looks like that username is already in use, please try again.", delegate: self, cancelButtonTitle: "Try again")
}
}
}
最佳答案
有几种方法可以做到这一点。我的做法如下。
第一步。 好的,您要选择注册 View Controller 。 第2步。 您将控制单击并从黄色 View Controller 图标拖动到第二个 View Controller 。在出现的菜单中选择显示或呈现模式选项。
第 3 步。 选择您刚刚创建的 Segue 并更改其标识符,在右侧面板中将其更改为“signupSuccessful”。
第 4 步。 您可以像这样设置代码。
if usernameTF.text.isEmpty || passwordTF.text.isEmpty {
var emptyFields = UIAlertView()
emptyFields.title = "Plese try again"
emptyFields.message = "It looks like you forgot to fill out all the fields. Please make sure all the fields are filled out so we can create an account for you."
emptyFields.addButtonWithTitle("Try Again!")
emptyFields.show()
}else if usernameTF.text == "ERROR CODE 203" {
//do same thing with the alert view!
}else if usernameTF.text == "ERROR CODE 202" {
//Do another alert view here
//You can keep adding the "else ifs" for any other error codes
}
//Here is where it will send to the second view when everything above is false!
else {
//Here we present the second view.
self.performSegueWithIdentifier("signupSuccessful", sender: self)
}
给你。 如果您需要再次查看 segue 或上述任何代码,请下载该项目。
关于ios - 如果缺少字段,则解析注册到下一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32416531/