在我的应用程序中,我有一个 Collection View ,单元格有一个图像和按钮。 UIImage 代表用户想要下载的一本书。当用户单击单元格中的按钮时,我应该显示一个表示下载进度的进度 View 。 我的手机是一个 Nib 。 我的问题是管理所有这个单元格中的进度 View 。 当我单击一个单元格时,另一个单元格中显示进度条! 以前有人尝试过做类似的事情吗? 已编辑1: 我的 cellForItemAtIndexPath 是:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("guides-cell", forIndexPath: indexPath) as! GuidesViewCell
cell.guidesTypeLabel.text = guidesArray[indexPath.item].Title
cell.downloadLink = guidesArray[indexPath.item].Download1
cell.downloadButtonOutlet.addTarget(self, action: "downlaodAction:", forControlEvents: UIControlEvents.TouchUpInside)
cell.downloadButtonOutlet.tag = indexPath.row
编辑2:
我尝试从单元类调用下载函数,我获取按钮的操作导出,然后从中调用下载函数。 像这样:
@IBAction func downloadButtonAction(sender: AnyObject) {
FileIsdownloding = true
downloadActivityIndicator.alpha = 1
downloadActivityIndicator.startAnimating()
downloadProgressBar.alpha = 1
DownloadpdfsFilesControllerVar.downloadPDFFile(downloadLink, view:self, progressBarVar: downloadProgressBar, senderButton: sender as! UIButton)
}
我仍然遇到同样的问题。进度条显示在随机单元格中!!!! 那是糟糕的!
我将感谢任何帮助。
最佳答案
cell.downloadButtonOutlet.addTarget(self, action: "downlaodAction:", forControlEvents: UIControlEvents.TouchUpInside)
从 dequeueReusableCellWithReuseIdentifier
中提取的单元格之前可能已被使用过。
addTarget(action:forControlEvents:)
添加目标。它不会删除旧的。您需要包括:
cell.downloadButtonOutlet.removeTarget(nil)
清除旧目标。您当前的代码可能正在为该单元曾经使用过的每个目标调用操作。
关于ios - 管理 Collection View 单元格中的多个进度 View Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31835034/