簡體   English   中英

如何使此功能正常運行

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM