[英]Swift - how automatically select cell when collectionView first loads up?
I'm trying to figure out how to programmatically select a cell the moment the collectionView starts up. 我试图弄清楚如何在collectionView启动时以编程方式选择一个单元格。 As in, the default load of the collectionView should have the first cell selected.
在中,collectionView的默认负载应该选择第一个单元格。
I'm using shouldSelectItemAtIndexPath for my selection function, so I want to call it for a specific cell index. 我正在使用shouldSelectItemAtIndexPath作为我的选择函数,所以我想为特定的单元格索引调用它。
So far I have tried: 到目前为止,我尝试过:
collectionView(self.collectionView!, shouldSelectItemAtIndexPath: self.collectionView!.indexPathForCell(CVcellArray.first!)!)
In my viewDidLoad function for my custom CollectionView script. 在我的viewDidLoad函数中为我的自定义CollectionView脚本。
It crashed when the collectionView loaded. 它在加载collectionView时崩溃了。 Am I doing something wrong?
难道我做错了什么?
Thank you. 谢谢。
在viewDidAppear
只需调用selectItemAtIndexPath
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.