我想在创建 UIAlertController 后更改它的消息。在警报中,我想显示下载状态。
@IBAction func dbWillSync(sender: AnyObject) {
alert = UIAlertController(title: "SYNC",
message: "0%",
preferredStyle: .Alert)
let dismissHandler = {
(action: UIAlertAction!) in
self.dismissViewControllerAnimated(true, completion: nil)
}
alert.addAction(UIAlertAction(title: "STOP DOWNLOAD",
style: .Cancel,
handler: dismissHandler))
presentViewController(alert, animated: true, completion: nil)
download();
}
func download(){
for i in 1...100{
alert.message="\(i) %"
sleep(1)
}
}
怎么了 ?
谢谢
*编辑*****
我不知道这是否是最好的解决方案:
let thread = NSThread(target:self, selector:"download", object:nil)
thread.start()
..但它的工作原理!
欢迎改进!