在 swift 更新 UIprogressView
Update UIprogressView in swift
我有一个 uiprogressview 到 uicollectionview,我试图在选择一个单元格后更新 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()
}
这样好吗?,我该如何解决这个问题。
提前致谢
问题就在这里
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
}
我有一个 uiprogressview 到 uicollectionview,我试图在选择一个单元格后更新 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()
}
这样好吗?,我该如何解决这个问题。
提前致谢
问题就在这里
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
}