2017-04-17 71 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()解决了这个问题。

相关问题