在集合视图单元Swift中管理多个进度视图

时间:2015-08-05 14:13:46

标签: ios iphone swift uicollectionview

在我的应用程序中我有一个集合视图,单元格有一个图像和按钮。 UIImage代表用户想要下载的书。当用户单击单元格中的按钮时,我应该显示代表下载进度的进度视图。 我的手机是笔尖。 我的问题在于管理所有这个单元格中的进度视图。 当我点击一个单元格时,另一个单元格中显示的进度条!! 以前任何人都想尝试这样的事情吗? 的 Edited1 : 我的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            

Edited2

我尝试从单元类调用下载功能,我按下按钮的动作插座,然后从中调用下载功能。 像这样:

  @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)



}

我仍有同样的问题。进度条显示我随机细胞!!!! 太可怕了!

我会感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

cell.downloadButtonOutlet.addTarget(self, action: "downlaodAction:", forControlEvents: UIControlEvents.TouchUpInside)

dequeueReusableCellWithReuseIdentifier拉出的单元格之前可能已经使用过。

addTarget(action:forControlEvents:) 添加目标。它不会删除旧的。你需要包括:

cell.downloadButtonOutlet.removeTarget(nil)

清除旧目标。您当前的代码可能正在调用此单元格曾用于的每个目标的操作。

相关问题