【发布时间】:2016-10-24 10:06:03
【问题描述】:
我有要下载的NSMutableDictionary 数组列表。我正在使用cellForRowAtIndexPath 下载它们中的每一个。但是,当cellForRowAtIndexPath 运行时,所有的 zip 文件并行下载,这导致应用程序挂起、UI 冻结、CPU 使用率飙升。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:updateAllCell = tableView.dequeueReusableCellWithIdentifier("updateAllCell") as! updateAllCell!
let row = self.bookArray.objectAtIndex(indexPath.row) as! NSMutableDictionary
self.updateBookList(row, progressView: cell.downloadProgressView, labelView: cell.lblDownloadPercent)
}
func updateBookList(bookData: NSMutableDictionary, progressView: UIProgressView, labelView: UILabel) {
let source = Utility().getContentsDirectory().stringByAppendingString("/\(fileName).zip")
Alamofire.download(.GET, source, destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
println(totalBytesRead) // update progressView and labelView
}
.response { request, response, _, error in
println(response)
}
}
他们可以依次下载吗?谢谢。
【问题讨论】:
标签: ios swift uitableview alamofire