简体   繁体   English

Swift - 在collectionView首次加载时如何自动选择单元格?

[英]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.

相关问题 加载时Swift collectionview无法自动选择第一个单元格 - Swift collectionview cant automatically select first cell when load Swift CollectionView获取第一个单元格 - Swift CollectionView get first cell iOS:如何选择并滚动到swift 3中collectionView中的特定单元格? - iOS: How to select and scroll to a specific cell in a collectionView in swift 3? Swift 在第一个 collectionview 单元格中添加相机预览 - Swift Add camera preview in first collectionview cell Swift collectionView选择单元格多项选择 - Swift collectionView select cell multiple selection Swift如何在集合视图中获取中心单元格并在滚动时调整其大小? - Swift How to get the centre cell in a collectionView and resize it when scrolling? 在 Swift 4 中单击单元格时如何更改 CollectionView 之外的 textLabel? - How to change textLabel outside CollectionView when cell is clicked in Swift 4? 如何在 RxSwift 中选择 CollectionView 单元格 - How to select CollectionView cell in RxSwift 如何选择CollectionView中的最后一个单元格? - How to select the last cell in a CollectionView? iOS:在Swift3的collectionView中,当我向下滚动时,collectionView会自动位于顶部。 如何停止呢? - iOS: in Swift3, in my collectionView, when I scroll downstair, the collectionView comes automatically at the top. How to stop it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM