我有2个功能
func checkEmailField() -> Bool {
if(!loginPasswordTextField.text!.isEmpty){
return true
} else {
print("Empty Field was found")
// self.displayMessage(error.localizedDescription, fromViewController: self)
return false
}
}
和
func displayMessage(errorMessage:String?, fromViewController:UIViewController){
let titleMessage = "Error"
let alert = UIAlertController(title: titleMessage, message: errorMessage, preferredStyle: .Alert)
let actionOK = UIAlertAction(title: "Ok", style: .Default, handler: nil)
alert.addAction(actionOK)
fromViewController.presentViewController(alert, animated: true, completion: nil)
}
当我在第一个func()中取消注释该行时,我得到一个错误未解析的标识符错误...我如何通过错误以便它可以工作?
答案 0 :(得分:1)
因为您没有名为error
的变量。你displayMessage
函数需要一个字符串,所以只需传递一个字符串:
func checkEmailField() -> Bool {
if(!loginPasswordTextField.text!.isEmpty){
return true
} else {
print("Empty Field was found")
self.displayMessage("Empty field was found", fromViewController: self)
return false
}
}