UICollectionView完成加载后如何启动功能?

编程入门 行业动态 更新时间:2024-10-04 15:32:10
本文介绍了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完成加载后如何启动功能?

本文发布于:2023-11-26 23:16:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   功能   UICollectionView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!