Swift-首次加载collectionView时如何自动选择单元格? [英] Swift - how automatically select cell when collectionView first loads up?

查看:288
本文介绍了Swift-首次加载collectionView时如何自动选择单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何在collectionView启动时以编程方式选择一个单元格.与之类似,collectionView的默认加载应选择第一个单元格.

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.

我在选择功能中使用了shouldSelectItemAtIndexPath,因此我想针对特定的单元格索引调用它.

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!)!)

在我的自定义CollectionView脚本的viewDidLoad函数中.

In my viewDidLoad function for my custom CollectionView script.

在加载collectionView时崩溃.我在做错什么吗?

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

谢谢.

推荐答案

viewDidAppear中,只需调用selectItemAtIndexPath.

这篇关于Swift-首次加载collectionView时如何自动选择单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆