-1

I want to set a section header (an image as a section header) at a specific index path in my collectionView (after a certain number of cells).

Attempt to solve issue - So far when I try set the number of sections to 2 or more, it just duplicates the same cells. Also I can't find how to set the actual header. I know for a tableView it'd be titleForHeaderInSection (set the section header) and numberOfRowsInSection (set the rows for each section) but it doesn't work for a collectionView.

Question - How can I set a header at a specific index path

I'm using Swift 3

Nolan Ranolin
  • 409
  • 3
  • 16
  • 1
    You appear to have `2` questions here: `duplicated cells` and `collection view headers`. Any question on StackOverflow should only have `*1*` question so choose `1` and put the other in a different question. Also, have you done any research into how to add a section header to a collection view? There are hundreds of tutorials online. – Robotic Cat May 06 '17 at 20:46

1 Answers1

0

1. Setting image as section header You can achieve this by returning a view for collectionView:viewForSupplementaryElementOfKind: for kind if(kind == UICollectionElementKindSectionHeader).

2. Rows duplicating when you set number of sections to 2 You have to provide number of rows for each section.

Shaheen M Basheer
  • 1,010
  • 6
  • 11
  • I've got the number of numberOfItems in section set to the array.count I halved it but it now just shows half the cells and duplicates those visible. Also how can I set to where in the collectionView the header will be? – Nolan Ranolin May 06 '17 at 21:03
  • @NolanRanolin Its because, when you taking the objects from your datasource array, you are not taking section in to consideration. The first row of second section should be the count of rows in 1st section + 1. You need to do calculation like that. – Shaheen M Basheer May 06 '17 at 21:19
  • @NolanRanolin you can accept the answer, if it provided a solution for your issue. – Shaheen M Basheer May 07 '17 at 19:24
  • It almost has. I've got one array not two, that's why I'm not sure how to get the header where I want (where to start the second section), is it possible to set the second section of a collectionView to start at a specific index path? – Nolan Ranolin May 07 '17 at 19:38