刚刚添加了一个警报,最后得到了一个"需要声明"的错误,我已经在";"中添加了系统建议但仍然不起作用,代码如下:
class SignUpViewController: UIViewController {
@IBAction func BackToFirstPageButton(sender: AnyObject) {
performSegueWithIdentifier("BackToLogInPage", sender: self)
}
@IBOutlet var UsernameTextField: UITextField!
@IBOutlet var PasswordTextField: UITextField!
@IBOutlet var EmailTextField: UITextField!
@IBAction func SignUpButton(sender: AnyObject) {
if UsernameTextField.text == "" || PasswordTextField.text == "" || EmailTextField.text == "" {
let SignUpAlert = UIAlertController (title: "Error in form", message: "Please fill in the blanks", preferredStyle: UIAlertControllerStyle.Alert)
SignUpAlert.addAction((UIAlertAction(title: "Dismiss", style: .Default, handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
})))
self.presentViewController(SignUpAlert, animated: true, completion: nil)
}
func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
};
最后一个括号和冒号是我得到声明错误的地方。请帮忙。第一次在这里发帖,所以如果我遗漏了什么,请告诉我。谢谢
此方法中缺少一个右大括号
@IBAction func SignUpButton(sender: AnyObject) {
...
}
您可以将光标悬停在行号和代码之间的小列上(这会突出显示当前范围),或者在单击方法声明行左侧出现的小公开三角形时折叠方法来检查这一点。
看起来SignUpButton方法中的if语句缺少一个右括号
尝试:
class SignUpViewController: UIViewController {
@IBAction func BackToFirstPageButton(sender: AnyObject) {
performSegueWithIdentifier("BackToLogInPage", sender: self)
}
@IBOutlet var UsernameTextField: UITextField!
@IBOutlet var PasswordTextField: UITextField!
@IBOutlet var EmailTextField: UITextField!
@IBAction func SignUpButton(sender: AnyObject) {
if UsernameTextField.text == "" || PasswordTextField.text == "" || EmailTextField.text == "" {
let SignUpAlert = UIAlertController (title: "Error in form", message: "Please fill in the blanks", preferredStyle: UIAlertControllerStyle.Alert)
SignUpAlert.addAction((UIAlertAction(title: "Dismiss", style: .Default, handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
})))
self.presentViewController(SignUpAlert, animated: true, completion: nil)
}
}
func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
};
您需要添加最后一个右括号"}",然后您可以像Alessandro Chiarotto所说的那样删除";"
在swift中,您不需要';'类似objective-c