0

Im stuck with the problem to use both vertical and horizontal scroll direction in a UICollectionView in the same UIViewController.

What I've done so far is first a UICollectionView. In top of the UICollectionView I've got a Collection Reusable View. My solution is to implement an other UICollectionView inside of the reusable view but got errors when running the project.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath (UICollectionElementKindSectionHeader,<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil ((null))

So Im actually handling two different CollectionViews in one UIViewController in the same Delegate and Datasource methods.

It is a better approach to build it with a UITablewView? Than add the collectionviews to different UITableViewCells? Or better to start with an UIScrollView and then add two different UICollectionViews to the scrollview?

enter image description here

Martin Borstrand
  • 186
  • 1
  • 13

1 Answers1

0

AFTabledCollectionView

Refer above sample code

In this sample code. UITableView is there and UITableviewCell contains UICollectionView(With horizontal direction).

Some more detail from above sample code regarding to your problem

Take one 'UITableView' having 2 section. Its first section would have 'UICollectionView' and second section has 'UICollectionView'.

Payal Maniyar
  • 3,685
  • 20
  • 47
  • As I'm trying to explain in the picture I want to use both vertical and horizontal scroll. The top should be as an carousel and the rest as an normal vertical UICollectionView. – Martin Borstrand Apr 07 '16 at 11:08
  • Okey thanks, but is it possible to adjust the size of the "second" UITableViewCell to be as big as the number of CollectionViewCells inside of the UICollectionView? I tried with UITableViewAutomaticDimension but that will of course not work because the UICollectionViewCell wont be bigger even if there's a lot of cells. @payal-maniyar – Martin Borstrand Apr 07 '16 at 12:12
  • Set with constraint for tableview and give height like below line of code : `if(indexPath.section > 0) { return 210.0; } else { return 188; }` This way you will not face any issue. – Payal Maniyar Apr 07 '16 at 12:15
  • Yes of course I do if it seems to be right. But why should I set the height to 188 in section 2? @payal-maniyar I want it to be dynamic. Should be as big as all the cells in the collectionview. So 188 feels to small..? – Martin Borstrand Apr 07 '16 at 12:27
  • I gave you for example. You can set as much as height yo want. – Payal Maniyar Apr 07 '16 at 12:28
  • Yes I see .. But as I said the UITableViewAutomaticDimension doesn't work with this and I cant set it to a static height. If you want to look at the app TicTail you will see the exact same approach I want to do at their first page. @payal-maniyar – Martin Borstrand Apr 07 '16 at 12:31
  • I followed the steps from this question http://stackoverflow.com/a/33364092/1752699 and that worked out for me. Created two different UITableViewCells with two different UICollectionViewCells inside of each of them. Thanx! @payal-maniyar – Martin Borstrand Apr 07 '16 at 12:47
  • welcome. One problem can be solved by many ways. My solution is also correct because right now I am working on it. I have just it implemented before 2 days. – Payal Maniyar Apr 07 '16 at 12:55
  • Okey great! Would you like to share your code in some way so I can look at your solution? Can share my solution as well. @payal-maniyar – Martin Borstrand Apr 07 '16 at 13:26