2017-04-17 72 views
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更新。

+0

希望在調用self.CollectionView.reloadData() – BaSha

+0

之前確保imageArray已加載,那麼您的問題是什麼? reloadData不工作或者它沒有被調用? – adam

+0

檢查ViewDidAppear和PrepareForSegue方法是否在您從其他視圖返回到此視圖時被調用。 –

回答

0

在ViewDidAppear中調用ViewDidLoad()解決了這個問題。

相關問題