2

Long story short. I have a ViewController that has a ColletionView that's the main component of the page. The CollectionView has 2 reusable cell a Header and a Footer. I would like to have a TableView inside the footer but that's not possible I get the following error when I try to connect the TableView:

"Illegal Configuration: The tableView outlet from the ViewController to the UITableView is invalid. Outlets cannot be connected to repeating content."

My tip is that I want to achieve this in a total wrong way.

I want to achieve the following:

enter image description here

Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41
  • Maybe this is helpful: https://stackoverflow.com/questions/26561461/outlets-cannot-be-connected-to-repeating-content-ios – koen Jul 02 '19 at 12:32
  • @richard I suggest you to take separate tableView and collectionView for better experience even you can achieve this in your way but It might be some tricky and difficult. – Shiv Jaiswal Jul 02 '19 at 13:12
  • @ShivJaiswal I want to use this method because I want to have a dynamically growing CollectionView (item number) + I want to have a single scroll page. – richardtulkan Jul 02 '19 at 13:16
  • @richardtulkan Oh..then I suggest you to use collectionView within tableView, it is bit easy compare to vice versa. – Shiv Jaiswal Jul 02 '19 at 13:25
  • @richardtulkan - You should be able to use a "normal" `UIView`, with a table view as a subview, as the collection view footer view ***instead*** of a *reusable* view. Then it won't be repeating content, and you should be able to connect your table view properly. – DonMag Jul 02 '19 at 13:30
  • @ShivJaiswal Thank you for your answer, I know it would be easier but then I would not be able to change the Header's height dynamically.(When I want to display more CollectionView Cell) :/ Any idea for that? – richardtulkan Jul 02 '19 at 13:30

2 Answers2

1

[SOLVED]

The solution was the following: I made a CollectionReusableView file for the Footer then exactly when @karem_gohar said I passed the following:

footer.tableView.delegate = footer.self footer.tableView.dataSource = footer.self

I connected the tableView to the CollectionReusableView, I made an array to test it out I filled the tableView with the elements of the array.

Ps.:I made a TableViewCell and linked a label to it. The label showed the element of the array.

0

I assume you did register the footer/header nib like this:

segmentCollectionView.register(UINib(nibName: /* CellNibName */, bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: /* CellId */)

and then dequeue the cell like this

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    if kind == UICollectionView.elementKindSectionFooter {
        let cell = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: /* CellId */, for: indexPath) as! /* Your Class */
    } 
    else {
    }
}
  • so the trick is in your registered cell class as a footer you can go to the xib file and add the UITableView inside the reference /* Your Class */
  • link the UITableView in the cell class not theUIViewControllerclass that contains theUICollectionView`
  • then pass the data you want when you dequeue the cell and perform all your business inside the cell class
koen
  • 5,383
  • 7
  • 50
  • 89
karem_gohar
  • 336
  • 1
  • 3
  • 11
  • Can't believe it but I solved it. Not exactly like you said it but because of you, thank you very much for your time and effort, I owe you. @karem_gohar – richardtulkan Jul 02 '19 at 15:47
  • @richardtulkan you are welcome, just make sure when you got the knowledge to pass it on to other people :-) – karem_gohar Jul 03 '19 at 07:25