Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Hey Treehouse, is it possible to put a CollectionView inside of a CollectionViewCell using "STORYBOARD?" with SWIFT 3

I know it's possible doing it just programmatically, getting rid of "Storyboard / Main" and creating a window in the AppDelegate. But, Can this be done using "STORYBOARD" with SWIFT 3?

A collectionview cell is just a collection of objects basically and a collection view is a object at the end of the day, but why would you put a collection view inside of a collection view cell? You are making inception because:

1- Collection View[ 1a - collectionView Cells[ 2- colllectionView[ 2a - collection view cell ] ] ]

what's going in that final cell(2a)?

FIRST OF ALL -Thank you very much -just for taking the time to respond to my first question -I appreciate it. -THANKS.

But there's an issue. Your answer is unclear to me - I want to create a CollectionView with 2 Cells, inside of a UIViewController. (I got that part working fine) - The problem I'm having is: I want to put a 2nd CollectionView with 6 Cells in the second Cell of the first CollectionView. I dragged the 2nd CollectionView inside the second Cell of the first CollectionView, When I RUN it, -It runs fine, I see the 2nd CollectionView inside the second Cell. -BUT the 2nd CollectionView doesn't display its CELLS.

PROBLEM: I am stuck on getting the 2nd CollectionView to display the 6Cells I want, while in the first CollectionView's second cell. RIGHT NOW; the 2nd CollectionView doesn't display any cell at all, it just shows up blank / empty

How can I CONNECT the 2nd CollectionView to its own DataSource & Delegate? and How can I get the 2nd CollectionView to display it cells?

THANKS FOR YOUR HELP, BRO.

1 Answer

Okay so what you need to do is this:

  • Create a collection view where both cells are regular UIViews(so now you have consistent content in the two cells)
  • You got cell 1 working fine so we good here
  • in cell two which is a UIView we need to add a Collectionview controller INSIDE that view as a child view.

In code you would just call addSubView and pass in the second collection view to that view you have in the second cell.

Now with storyboards what you could do is create a whole separate collection view get it up and running and in that second cell(which is a UIView) you can use a container view and add that to the cell.

https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

Hope this helps. Also I'm sorry if I confuse.