我正在使用swift向我的服務器發送消息,但是,當它結束時,我無法獲得警報彈出窗口。這是代碼。試圖加載視圖時不允許釋放分配
func sendSimpleCommand(siteId: Int, command: String) -> Int {
Alamofire.request(.GET, commandUrl, parameters: ["site": siteId, "command": command, "device": "ios"])
.responseJSON { response in
//print(response.result) // result of response serialization
switch response.result {
case .Success(_):
print("success code back from api server for command sent")
let alertView = UIAlertController(title: "Command Sent", message: "Your \(command) has been sent.", preferredStyle: .Alert)
let alertAction = UIAlertAction(title: "OK", style: .Default) { _ in
}
alertView.addAction(alertAction)
case .Failure(_):
print("FAIL code back from api server for command sent")
let alertView = UIAlertController(title: "Connect Error", message: "Network error, please try again", preferredStyle: .Alert)
let alertAction = UIAlertAction(title: "OK", style: .Default) { _ in
}
alertView.addAction(alertAction)
}
}
return 1
}
@IBAction func startButtonTouch(sender: UIButton) {
let helper = HelperActions()
let site = ActiveSite.sharedInstance.siteObject
let command: String = "start"
sendSimpleCommand(site.id , command: command)
}
現在,當我運行它時,網絡通信正常發生,但然後我得到一個錯誤,警報窗口從不出現。
試圖同時它解除分配是不允許的,可能會導致不確定的行爲
alertView的所有聲明你是哪裏試圖呈現呢? – dan
在UIViewController中 – skrite