CollectionView在Swift中的randomIndex中填充

时间:2016-09-24 16:18:33

标签: swift uicollectionview

我有一个成功运行的colllectionView,它从web链接中抓取url图像内容。我试图在每次查看loads.my尝试按随机索引填充collectionView,如下所示...

override func viewDidLoad() {
    super.viewDidLoad()

 self.collectionView.reloadData()
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

   let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath) as! Cell

    let randomIndex = Int(arc4random_uniform(UInt32(apps.count)))

    cell.app = apps[randomIndex] as? AppInfo

    return cell
}

上面的方法每次页面滚动时重新加载collectionView。我试图只重新加载一次......

提前致谢....

0 个答案:

没有答案