0
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! LevelSelectCVC
cell.imageView?.image = imageArray[indexPath.row]
if indexPath.item >= stageProgress {
cell.imageView?.image = UIImage(named: "Lock Icon Grey")
} else {
cell.imageView?.image = imageArray[indexPath.item]
}
return cell
}
當在該函數I檢查整數stageProgress
的值和從UIImage
陣列到collection view cells
增加圖象的相同的量。其餘的單元格添加默認UIImage
。從另一個view controller
返回後,我必須檢查stageProgress
並從陣列中添加另一個UIImage
。重新加載集合視圖返回到先前的視圖控制器
有誰知道我該怎麼做?我試圖做的事:
self.CollectionView.reloadData()
在這兩個ViewDidAppear和PrepareForSegue
如果我重新啓動遊戲的CollectionView更新。
希望在調用self.CollectionView.reloadData() – BaSha
之前確保imageArray已加載,那麼您的問題是什麼? reloadData不工作或者它沒有被調用? – adam
檢查ViewDidAppear和PrepareForSegue方法是否在您從其他視圖返回到此視圖時被調用。 –