UICollectionView完成加载后如何启动功能? [英] How can I start function when UICollectionView is finished loading?

查看:56
本文介绍了UICollectionView完成加载后如何启动功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

   cell.news = homePageViewController.sliderList[indexPath.row]

   let returnleft = IndexPath(row: 0, section: 0)

   self.collectionView.scrollToItem(at: returnleft, at: UICollectionViewScrollPosition.left, animated: true)

   return cell  
}

加载 UICollectionView 后如何使用 returnleft ?

let returnleft = IndexPath(row: 0, section: 0)

self.collectionView.scrollToItem(at: returnleft, at: UICollectionViewScrollPosition.left, animated: true)

cellForItemAt

推荐答案

cellForItemAt 仅用于在表格视图中创建单元格.将为表中的每个单元格调用一次(不一定要一次调用,而是滚动到表视图时调用).

cellForItemAt is to be used only to create the cells in your table view. It will be called once for each cell in your table (not necessarily at once, but as you scroll into the table view).

因此,将代码移到下面更合适的位置,例如 viewDidLoad .

So move your code below in a more appropriate place, like viewDidLoad.

let returnleft = IndexPath(row: 0, section: 0)
self.collectionView.scrollToItem(at: returnleft, at:UICollectionViewScrollPosition.left, animated: true)

这篇关于UICollectionView完成加载后如何启动功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆