0
我有NSMutableDictionary
我想要下载的数组列表。我正在使用cellForRowAtIndexPath
来下载它们中的每一个。但是,当cellForRowAtIndexPath
运行时,并行下载的所有zip文件都会导致应用程序挂起,UI冻结,CPU使用率通过屋顶。Alamofire:如何在UITableView中顺序下载zip文件
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)
}
}
他们可以一个接一个顺序下载吗?谢谢。
现在,我通过删除NSmutableDictionary得到了结果。 在cellForRowAtIndexPath中,我检查了indexPath.row。 if indexPath.row == 0 {self.updateBookList(row,...)} 在updateBookList中,我像“self.bookArray.removeObject(bookData)”一样被删除。感谢您的回复。 –
对不起,解决您在评论中遇到的问题有点难。就我个人而言,我认为你应该重新考虑下载“cellForRowAtIndexPath”,因为这也意味着每次新单元出现时(即滚动时)都会触发下载。 – PeterB