【问题标题】:Progress View not updating进度视图未更新
【发布时间】:2017-01-23 12:16:15
【问题描述】:

我正在尝试从返回完成百分比的进度块(解析)中获取进度视图。

当我打印百分比时,我得到:

16.0
17.0
18.0
ect

所以它正在返回,当我打印 progressBar.progress 时,我得到:

0.0
all the way to 
1.0

但是进度条还是没有更新:

}, progressBlock: { (percent) in
   // print(Float(percent))
    DispatchQueue.main.async {
        cell.progressBar.setProgress(Float(percent/100), animated: true)
            //print(cell.progressBar.progress)
    }

//cell.progessBar.progress = Float(percent)

if percent == 100 {
    cell.progressBar.isHidden = true
}

})

请注意,单元格是这样定义的自定义单元格:

func didDoubleTap(gesture: UITapGestureRecognizer) {

    let point: CGPoint = gesture.location(in: self.collectionView)

    if let selectedIndexPath: IndexPath = self.collectionView.indexPathForItem(at: point) {
        // let selectedCell: UICollectionViewCell = self.collectionView.cellForItem(at: selectedIndexPath as IndexPath)!
        // let indexItem = selectedIndexPath[1]
        // create instance of the cell so we can manipulate the images
        let cell: JourneyCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: selectedIndexPath) as! JourneyCollectionViewCell

【问题讨论】:

  • 我很好奇 - 我在 Dispatch 异步块中没有看到对 self 的调用,您是否尝试从可重用单元格中的闭包更新渐进式?如果是这样,您可能希望在 cellForRow 方法之外的特定索引路径处耦合进度视图。
  • 我不完全确定。我刚刚阅读了另一个线程中对调度队列的引用,并徒劳地添加了它。你能解释一下你所说的“耦合”索引方法的单元格外部的进度视图是什么意思吗?
  • 这实际上是一个自定义函数,我在集合视图中应用了双击手势,而不是覆盖
  • 您能否在您的问题中添加更多单元的实现?
  • 当然,我更新了问题。下面只是查询代码,如果需要我可以添加,但这里有点长。

标签: ios swift progress-bar


【解决方案1】:

你正朝着正确的方向前进。单元格定义有问题。

使用创建的索引没有拒绝允许编辑单元格。

let cell: JourneyCollectionViewCell = self.collectionView.cellForItem(at: selectedIndexPath ) as! JourneyCollectionViewCell

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2014-12-19
    • 2021-09-09
    • 2015-06-26
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    相关资源
    最近更新 更多