ios - 管理 Collection View 单元格中的多个进度 View Swift

标签 ios iphone swift uicollectionview

在我的应用程序中,我有一个 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/

相关文章:

ios - ScrollView 中的内容随着导航菜单的高度值向下移动

ios - UIPageViewController - 以编程方式更改页面在 iPhone 4s/5/5s 上不起作用

ios - iPhone 无法通过 WiFi 连接到本地 HTTP 服务器

ios - 将 Firebase 通知与本地通知 iOS 结合使用

ios - Firebase 如何检查快照的子级本身是否属于 Datasnapshot 类型

iphone - 如何切换 ViewController 而不是添加到堆栈?

iphone - 创建 Tableview 的自定义背景的正确方法

iOS 应用深度链接 : Return to previous app or access current url scheme of current app

ios - Xcode 更新后过渡停止工作

ios - 将 url 添加到 OHAttributedLabel 但未调用 shouldFollowLink 委托(delegate)