我试图调用一个AlertController,一旦Post发布到我的PHP站点,就会向用户显示一条消息。我在调用IBAction Button内的AlertController时遇到问题。在此先感谢您的帮助。我确定我错过了一些基本的东西。
以下是我的代码片段。
//Button Press Function
@IBAction func UPDATE_BTN(_ sender: UIButton) {
let SSID = SSID_INPUT.text
let PASS = PASS_INPUT.text
//Call SSID and PASS Valid to Check Length
let ssid_return = isSSIDValid(SSID!)
let pass_return = isPasswordValid(PASS!)
//If They Pass, Then Send to Web Server
if(ssid_return && pass_return)
{
print("Valid, Sending Info")
//Send Info to Webserver to Update Info
SEND_POST(SSID: SSID!,PASS: PASS!)
//This is where I want to call the ALERT....
func viewDidAppear(_: animated: Bool){
CreateAlert(title: "TEST", message: "IT WENT THROUGH")
}
}
//Otherwise Send User Error
else {
//Also Call Another Alert Here To Say It Didn't Post...
print("Not Valid")
}
}
这是我的AlertController的代码
//Alert Function
func CreateAlert (title:String, message:String){
let Alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
Alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {(ACTION) in
Alert.dismiss(animated: true, completion: nil)
}))
self.present(Alert, animated: true, completion: nil)
}
答案 0 :(得分:0)
更改您的CreateAlert功能,如下所示
func CreateAlert(title: String, message: String) {
let alertController = UIAlertController(title: title, message:
message, preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
}