简体   繁体   中英

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?

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. In fact, collectionviews use "sections" and "cells" to organize your data visually. 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. Just follow the Apple docs...

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

Use UICollectionElementKindSectionHeader to represent your blue items, and UICollectionViewCell to represent your yellow items. NExpandableCollectionView will expand and show the yellow items when a corresponding blue item is clicked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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