我在这一行有一个“预期的声明”:
if(userEmail.isEmpty || userPassword.isEmpty || userRepeatPassword.isEmpty)
你能告诉我为什么吗?先感谢您。
我的代码:
类RegisterPageViewController:UIViewController {
@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
@IBOutlet weak var repeatPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func registerButtonTapped(_ sender: AnyObject) {
let userEmail = userEmailTextField.text;
let userPassword = userPasswordTextField.text;
let userRepeatPassword = repeatPasswordTextField.text
}
//检查空白字段
if(userEmail.isEmpty || userPassword.isEmpty || userRepeatPassword.isEmpty)
{
// Display Alert Message
displayMyAlertMessage("All fields are required");
return;
}
最佳答案
在类中甚至全局声明变量,而不是在按钮内部!
var userEmail: String = ""
var userPassword: String = ""
var userRepeatPassword: String = ""
按钮声明:
@IBAction func registerButtonTapped(_ sender: AnyObject) {
userEmail = userEmailTextField.text;
userPassword = userPasswordTextField.text;
userRepeatPassword = repeatPasswordTextField.text
}