我正在使用位于github上的名为VegaScrollFlowLayout的库。我试图在我的collectionView中给出一个确切的索引,并显示从该索引开始的数据,但我不断将重置返回到索引0,而不是索引10。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
collectionView.scrollToItem(
at: NSIndexPath(item: 10, section: 0) as IndexPath,
at: [],
animated: false)
}
您可能应该打scrollToItem(at:at:animated:)
进来viewDidAppear()
,而不是viewWillAppear()
。在viewWillAppear()
集合视图中尚未显示任何单元格。我认为您不需要这样的延迟。
使用延迟是一种脆弱的工作方式。最好将代码移至正确的生命周期方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句