如何仅使用静态单元格创建集合视图? [英] How to create a collection view with static cells only?

查看:21
本文介绍了如何仅使用静态单元格创建集合视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个包含 7 个静态单元格的垂直集合视图.我知道如何动态执行此操作,但我看不到这样做的理由.

I want to add a vertical collection view that contains 7 static cells. I know how to do it dynamically, but i don't see a reason to do so.

我必须使用 cellForRow 方法吗?我向我的 viewController 添加了一个集合视图,并添加了 4 个单元格,将委托从 collectionView 连接到 vc(使用 storyBoard),但是当我运行它时,它显示了一个空的 collectionView.

Do i have to use the cellForRow method? I Added a collection view to my viewController, and added 4 cells, wired up the delegate from the collectionView to the vc (using storyBoard), but when i run it it shows me an empty collectionView.

我确实将 numberOfSections 设置为返回 1,将 numberOfCellsInSection 设置为返回 7.所以我错过了什么吗?还是我必须符合 DataSource 协议并实现 cellForRow 方法?(在 TableView 中,我可以在使用静态单元格时跳过 cellForRow).

I did set up the numberOfSections to return 1 and the numberOfCellsInSection to return 7. So did i miss anything? or do i have to conform to DataSource protocol and implement the cellForRow method ? (in TableView i can skip the cellForRow when using static cells).

感谢您的帮助.

推荐答案

来自官方 文档:

每个集合视图都必须有一个数据源对象.数据源object 是您的应用程序显示的内容.它可能是一个对象来自您应用程序的数据模型,或者它可能是视图控制器管理集合视图.数据源的唯一要求是它必须能够提供该集合的信息视图需求,例如有多少项以及要使用哪些视图显示这些项目时.

Every collection view must have a data source object. The data source object is the content that your app displays. It could be an object from your app’s data model, or it could be the view controller that manages the collection view. The only requirement of the data source is that it must be able to provide information that the collection view needs, such as how many items there are and which views to use when displaying those items.

这篇关于如何仅使用静态单元格创建集合视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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