Swift - how automatically select cell when collectionView first loads up?

时光总嘲笑我的痴心妄想 提交于 2019-12-12 18:18:44

问题


I'm trying to figure out how to programmatically select a cell the moment the collectionView starts up. As in, the default load of the collectionView should have the first cell selected.

I'm using shouldSelectItemAtIndexPath for my selection function, so I want to call it for a specific cell index.

So far I have tried:

collectionView(self.collectionView!, shouldSelectItemAtIndexPath: self.collectionView!.indexPathForCell(CVcellArray.first!)!)

In my viewDidLoad function for my custom CollectionView script.

It crashed when the collectionView loaded. Am I doing something wrong?

Thank you.


回答1:


In viewDidAppear just call selectItemAtIndexPath.



来源:https://stackoverflow.com/questions/34864679/swift-how-automatically-select-cell-when-collectionview-first-loads-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!