如果使用URLSession下载文件,然后
// Here you get finish download notification.
func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
// 1 save file at track index(get from original download URL) and do your other app changes
//... save
dispatch_async(dispatch_get_main_queue(), {
// 2 Reload row of trackIndex
self.tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: trackIndex, inSection: 0)], withRowAnimation: .None)
})
}
您无需承担显示器的进步和donw下载按钮,独立的单元。在tableView(_:cellForRowAtIndexPath:)
// Check local file exist or not
let downloaded = localFileExistsForTrack(track)
// Set UI accordingly
var showDownloadControls = false
if let download = activeDownloads[track.previewUrl!] {
showDownloadControls = true
cell.progressView.progress = download.progress
cell.progressLabel.text = (download.isDownloading) ? "Downloading..." : "Paused"
}
cell.progressView.hidden = !showDownloadControls
cell.progressLabel.hidden = !showDownloadControls
入住很好的例子,该任务nsurlsession-tutorial-getting-started
[NSNotificationCenter(https://developer.apple.com/reference/foundation/nsnotificationcenter)应该帮助 – paper1111