Within UITableView
, I have a custom cell with download button. Once Download button is tapped, I update the tag with indexPath.row
and in download function progress view is displayed in that cell. The problem is when user scrolls and cell becomes invisible, that specific progress view starts showing in a different cell.
This is my cellForRowAtIndexPath
function:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:CellWithDownload! = tableView.dequeueReusableCellWithIdentifier("CellWithDownload") as CellWithDownload
var title = rowDataAll[indexPath.row].valueForKey("BayanTitle") as String
cell.TitleLabel.text = title
cell.AuthorLabel.text = rowDataAll[indexPath.row].valueForKey("Artist") as? String
var countOfLikesString =
cell.downloadButton.tag = indexPath.row
cell.downloadButton.addTarget(self, action: Selector("downloadAudio:"), forControlEvents: UIControlEvents.TouchUpInside)
// If cell becomes visible again, then star
if let isDownloading = rowDataAll[indexPath.row].valueForKey("isDownloading") {
if (isDownloading as NSString == "true") {
cell.showDownloading()
cell.progressView.progress = getDownloadObjectWithURL(url).progress
} else if (isDownloading as NSString == "completed") {
cell.hideDownloading()
}
}
return cell
}
Please advice.