问题描述
我需要在注册表单中进行多文本字段验证。我有一个验证器,当文本字段中的文本无效时会抛出错误,并且我有验证所有文本字段的功能
func validateTextFields() {
do {
let email = try emailTextField.validatedText(validationType: ValidatorType.email)
let userName = try userNameTextField.validatedText(validationType: ValidatorType.userName)
let birthday = try birthdayTextField.validatedText(validationType: ValidatorType.birthday)
let password = try oldPasswordTextField.validatedText(validationType: ValidatorType.password)
} catch ValidationError.InvalidEmail {
emailTextField.showErrorLabel(error: "Invalid email")
} catch ValidationError.UserNameIsTooShort {
userNameTextField.showErrorLabel(error: "UserName is too short")
} catch ValidationError.InvalidPassword {
oldPasswordTextField.showErrorLabel(error: "Invalid password")
} catch ValidationError.InvalidBirthday {
birthdayTextField.showErrorLabel(error: "Invalid Birthday")
} catch let error {
#if DEBUG
print(error.localizedDescription)
#endif
}
}
该函数的问题在于它捕获了一个错误然后停止工作,而我在表单中只看到一个错误标签。我应该如何快速进行多个文本字段验证。我应该抛出验证错误还是可以使用布尔值进行验证。我想用 IBOutletCollection 制作它,但我不知道如何让文本字段知道它应该为循环传递什么样的验证
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)