gpt4 book ai didi

ios - 申请表中的登记表

转载 作者:行者123 更新时间:2023-11-29 01:03:56 24 4
gpt4 key购买 nike

所以我的应用程序中有注册表单,但是有问题。这是我的代码:

@IBAction func registerButtonAction(sender: AnyObject) {
if (fullnameTextField.text == ""){
self.fullnameTextField.shake()
}
if (usernameTextfield.text == ""){
self.usernameTextfield.shake()
}
if (usernameTextfield.text?.characters.count < 6){
usernameTextfield.shake()
}
if (emailTextfield.text == ""){
self.emailTextfield.shake()
}
if (passwordTextfield.text == ""){
self.passwordTextfield.shake()
}
if (retypepasswordTextfield.text == ""){
self.retypepasswordTextfield.shake()
}
else{
registerButton.setTitle("Registering user...", forState: UIControlState.Normal)
registerButton.alpha = 0.20
registerButton.enabled = false
registerUser()
}
}

首先:我能否使这段代码更小、更简单?其次,如果所有 UITextField 都有文本,并且 usernameTextFieldpasswordTextField 的字符数超过 6,我希望用户只启动 registerUser()。还有如何解决 passwordTextFieldretypepasswordTextfield 在注册前有相同的文本?有什么建议吗?

最佳答案

我认为这样更好一些:

@IBAction func registerButtonAction(sender: AnyObject) {
let validInput = true
let allTextFields = [fullnameTextField, usernameTextfield, emailTextfield, passwordTextfield, retypepasswordTextfield]
for textField in allTextFields {
if textField.text == "" {
validInput = false
textField.shake()
}
}

let theTextFieldsWithMin6Characters = [usernameTextfield, passwordTextfield]
for textField in theTextFieldsWithMin6Characters {
if textField.text?.characters.count < 6 {
validInput = false
textField.shake()
}
}
if passwordTextfield.text != retypepasswordTextfield.text {
validInput = false
retypepasswordTextfield.shake()
}

if validInput {
registerButton.setTitle("Registering user...", forState: UIControlState.Normal)
registerButton.alpha = 0.20
registerButton.enabled = false
registerUser()
}
}

关于ios - 申请表中的登记表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36654598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com