[英]Refresh collectionView on viewdidload after retrieving UserDefaults
[英]CollectionView Content View does not update/ refresh when viewdidload
我想在每個 collectionviewcell 中都有這個進度視圖(pod) 。 當我運行應用程序時,進度為 0%,它應該以 100% 的動畫進行測試,但它保持在 0%。 只有當我上下滑動(刷新單元格???)它開始動畫到 100%。 這是我的代碼:
import UIKit
import MKRingProgressView
class myCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var ringView: UIView!
let ringsize = 150
var ringProgressView = RingProgressView()
override func layoutSubviews() {
ringProgressView = RingProgressView(frame: CGRect(x: 0, y: 0, width: ringsize, height: ringsize))
ringProgressView.startColor = .red
ringProgressView.endColor = .magenta
ringProgressView.ringWidth = CGFloat(ringsize) * 0.15
ringProgressView.progress = 0.0
ringProgressView.shadowOpacity = 0.5
ringView.addSubview(ringProgressView)
}
}
extension myCollectionViewCell{
func setProgress(progress: Double){
UIView.animate(withDuration: 0.5){
self.ringProgressView.progress = progress
}
}
}
import UIKit
private let reuseIdentifier = "Cell"
class myCollectionViewController: UICollectionViewController {
@IBOutlet var myCollectionView: UICollectionView!
var cellColor = true
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return 7
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! myCollectionViewCell
cell.setProgress(progress: 1.0)
return cell
}
}
在viewDidAppear
方法中調用myCollectionView.reloadData()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.