【发布时间】:2016-07-08 05:40:13
【问题描述】:
我试图在用户按下按钮以在数据库中插入文本时显示警报,一切正常,但是当我得到响应并尝试在警报中显示它时,它不会立即工作,警报会在按下按钮后,我按下屏幕上的某个位置。我需要它在按下按钮后立即出现,如果我打印相同的响应它可以正常工作,但是当我使用警报时它不会。
@IBAction func posting(sender: AnyObject) {
let request = NSMutableURLRequest(URL: NSURL(string: "https://example.com/appapi/test2.php")!)
request.HTTPMethod = "POST"
let postString = "a=\(title.text!)"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error inenter code here
if error != nil {
print("error=\(error)")
return
}
let responseString = "\(NSString(data: data!, encoding: NSUTF8StringEncoding)!)"
self.displayR(responseString)
}
task.resume()
}
func displayR(str:String){
var alert = UIAlertController(title: "Description", message: "\(str)" ,preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in }))
self.presentViewController(alert, animated: true, completion: nil)
}
【问题讨论】:
标签: ios xcode swift swift2 uialertcontroller