0
votes

I have UITableViewController with 1 section and header with UISegmentedControl inside.

If user presses first segment we should display UITableView cells

If user presses second segment we should display custom vertical scrolling collection grid with collection items below that header

possible solutions:

  1. change UITableViewController to UICollectionViewController, and UITableViewCells to UICollectionViewCells. This should work but I'm trying to avoid this solution

  2. UICollectionView embedded in UITableViewCell. Setting UICollectionView scrolling enabled to false, adjusting UITableViewCell's height to fit entire UICollectionView's contentSize.height. In systemLayoutSizeFitting(...) method of container (UITableViewCell) we call layoutIfNeeded on container and on contained UICollectionView and return UICollectionView's contentSize.

    problem:

    (re)calculation of entire UICollectionView contentSize requires a lot of work if we have hundreds of items (cellForItemAtIndexPath for every item). Want to avoid this somehow. Maybe we can increase container (UITableViewCell) height during scrolling UICollectionView which is embedded inside.

  3. Same as 2 but we have fixed size container UITableViewCell (same height as view without header) with UICollectionView inside. When we scroll UITableView to the very bottom UICollectionView scroll should continue scrolling.

    problem:

    I don't understand how to deal with 2 instances of UIScrollView with scrollingEnabled = true for both. I think this could be solved with pan gesture recognizer delegates. If it is so I need help here.

1

1 Answers

0
votes

I would personally opt for number 1 and completely avoid number 2. For number 3, you could set tableView.scrollingEnabled = false when the second segment is tapped. Set it to true when the first segment is tapped. That way, when it's false, the UICollectionView in your UITableViewCell can still scroll.

This tutorial may help with putting a UICollectionView in a UITableViewCell.