Swift - how automatically select cell when collect

2019-07-11 18:23发布

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条回答
我命由我不由天
2楼-- · 2019-07-11 18:35

In viewDidAppear just call selectItemAtIndexPath.

查看更多
登录 后发表回答