我試圖在下載過程中實現顯示進度欄的警報消息。快速彈出警告彈出進度條
我發現這個代碼:
let alertView = UIAlertController(title: "Please wait", message: "Need to download some files.", preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
presentViewController(alertView, animated: true, completion: {
// Add your progressbar after alert is shown (and measured)
let margin:CGFloat = 8.0
let rect = CGRectMake(margin, 72.0, alertView.view.frame.width - margin * 2.0 , 2.0)
let progressView = UIProgressView(frame: rect)
progressView.progress = 0.5
progressView.tintColor = UIColor.blueColor()
alertView.view.addSubview(progressView)
})
但我不知道如何更新處理,更重要的,當下載完成後如何從這個警報退出過程中的進展(progressView.progress)。
任何幫助將不勝感激!
其實我只有項目要下載...但這是一個多部分HTTP POST,可能需要一些時間。我希望一旦HTTP請求完成(一旦收到結果),警報消息就會自動消失,我不希望最終用戶實際上單擊「確定」按鈕... – tiamat
強制執行最終用戶保持在下載狀態屏幕上。如果您在[Ray Wenderlich's](https://www.raywenderlich.com/79149/grand-central-dispatch-tutorial-swift-part-1)博客上查看如何使用GCD,可能會更好,並且只需要注意在單獨的線程中下載。 – NonCreature0714
我知道...但我需要填充一個UITableViewController從HTTP Post收到的數據我沒有選擇,否則最終用戶將需要拉tableView查看數據是最差的... – tiamat