[英]How to get this func to work Swift
我有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()中取消注释该行时,出现错误未解决的标识符错误...我该如何通过错误使其有效?
因为您没有名为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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.