简体   繁体   English

是否可以在iOS中嵌套集合/表视图?

[英]Is it possible to nest collection/table views in iOS?

I have a list of items (blue), and within each item there is a collection of sub items (yellow). 我有一个项目列表(蓝色),并且在每个项目中都有子项目的集合(黄色)。 Will it be possible to replicate this layout in iOS with collection and table views? 是否可以在iOS中使用集合视图和表格视图复制此布局?

I was going to create the blue items as a table view with custom cells. 我打算用自定义单元格将蓝色项目创建为表格视图。 Then within this custom cell (blue), I was going to place a collection view (yellow items). 然后,在这个自定义单元格(蓝色)中,我要放置一个集合视图(黄色项目)。

  1. Is this possible? 这可能吗?
  2. Is my choice of table view for the blue items and collection view for the yellow items correct? 我选择的蓝色项目表视图和黄色项目的集合视图正确吗?

See diagrams 见图表 在此处输入图片说明

More specifically, the layout will be like the following, varying content in each blue item and they are expandable, the yellow items becoming visible when the item has been expanded. 更具体地说,布局将如下所示,每个蓝色项目中的内容都不同,并且它们是可扩展的,黄色项目在扩展时变得可见。 在此处输入图片说明

UICollectionViews will work for both yellow and blue. UICollectionViews将适用于黄色和蓝色。 In fact, collectionviews use "sections" and "cells" to organize your data visually. 实际上,collectionview使用“ sections”和“ cells”以可视方式组织数据。 A section would be one of your "item groups" and a cell would be a "yellow square." 一个部分将是您的“项目组”之一,一个单元格将是“黄色正方形”。 The layout you have shown should be very simple to implement using UICollectionViewFLowLayoutDelegate methods. 使用UICollectionViewFLowLayoutDelegate方法实现的布局应该非常简单。 Just follow the Apple docs... 只需遵循Apple文档...

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CollectionViewBasics/CollectionViewBasics.html#//apple_ref/doc/uid/TP40012334-CH2-SW1 https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CollectionViewBasics/CollectionViewBasics.html#//apple_ref/doc/uid/TP40012334-CH2-SW1

I wrote a collection view subclass that can help you achieve that layout: https://github.com/nazeehshoura/NExpandableCollectionView 我编写了一个集合视图子类,可以帮助您实现该布局: https : //github.com/nazeehshoura/NExpandableCollectionView

Use UICollectionElementKindSectionHeader to represent your blue items, and UICollectionViewCell to represent your yellow items. 使用UICollectionElementKindSectionHeader表示蓝色项目,并使用UICollectionViewCell表示黄色项目。 NExpandableCollectionView will expand and show the yellow items when a corresponding blue item is clicked. 单击相应的蓝色项目时,NExpandableCollectionView将展开并显示黄色项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM