I have a uiprogressview into a uicollectionview, I'm trying to update the uiprogressview after selected a cell, but it does not update, this is my code:
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()
}
is it good?, how can I solve that problem.
thanks in advance
The problem is here
collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.myCell, for: indexPath) as! MyCell
You have to use 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
}