Declan McKenna
Declan McKenna

Reputation: 4870

How to create a TableViewCell with multiple UICollectionViews within it?

Hi I'm currently attempting to create a very complex TableViewCell which will be used once and presented at the top of our TableView. The view consists of 4x UILabel 2x UICollectionView 1x UIImage

I'm wondering whether this is feasible and what the best way to approach this is? enter image description here

I'm open to this not being a UITableViewCell but we want this to seamlessly scroll with the rest of the TableView, putting this within its own container above the TableView and within a UIScrollView was pretty messy as we had to handle the scrolling for both the scroll view and the tableview.

Upvotes: 2

Views: 69

Answers (1)

DonMag
DonMag

Reputation: 77423

OK - my suggestion would be...

  • Create a new ViewController - MyHeaderViewController
  • Layout this view, including the 2x UICollectionView
  • Get it working on its own

Once you've got that part going...

  • Create a new ViewController (can be a UITableViewController, or a UIViewController with a UITableView added)
  • add code in this controller to load MyHeaderViewController, and then set the tableHeaderView = myHeaderVC.view

That let's you keep all the logic for the Collection Views separate from the TableView

See https://github.com/DonMag/SWTableHeaderView for a simple example.

Upvotes: 1

Related Questions