在swift中更新UIprogressView

时间:2018-04-20 23:44:25

标签: ios swift uicollectionview uiprogressview

我对uicollectionview有一个uiprogressview,我在选择一个单元格后试图更新uiprogressview,但它没有更新,这是我的代码:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.myCell, for: indexPath) as! MyCell
            let timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true){
                (timer :Timer) in
                cell.progress.setProgress(cell.progress.progress + 0.1, animated: true)
                if cell.progress.progress >= 1 {
                    timer.invalidate()
                }
            }
            timer.fire()
    }

好吗?我该如何解决这个问题。

提前致谢

1 个答案:

答案 0 :(得分:1)

问题出在这里

collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.myCell, for: indexPath) as! MyCell

您必须使用cellForItem

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let cell = collectionView.cellForItem(at:indexPath) as! MyCell

//

if cell.progress.progress >= 1 {
    cell.progress.progress = 0.1
}