Alright, I am having trouble with a collection view here. This is what Im trying to achieve - 1 big MAIN header and footer, then nested inside there needs to be some number (ex: 4) sections that all have just HEADERS. Like this:
header main
------
tiny header 1
------
[a][b][c]
------
tiny header 2
------
[a][b][c]
footer main
Looking at similar answers I am first trying to just create different subsections since right now I just have all the collection view cells and a big footer and header. Problem is no matter what I have for this, I remain with only 1 SECTION:
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 4
}
I don't know why. I get my collection view from the storyboard and set it up like this:
@IBOutlet var collectionView: UICollectionView!
self.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) //-44
self.collectionView.backgroundColor = UIColor.white
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "headerCell", for: indexPath as IndexPath) as! HeaderCollectionReusableView
header = headerView
return headerView
case UICollectionElementKindSectionFooter:
let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "footerCell", for: indexPath as IndexPath) as! FooterCollectionReusableView
//footerView.center = CGPoint(x: footerView.center.x, y: footerView.center.y + 100)
return footerView
default:
assert(false, "Unexpected element kind")
}
}
// ADD STICKER TO CELL
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "stickerCell", for: indexPath as IndexPath) as! StickerCollectionViewCell
cell.backgroundColor = UIColor.blue
cell.initSticker(stickerView: stickerPack[indexPath.item])
cell.stickerName = (stickerPack[indexPath.item].sticker?.localizedDescription)!
cell.initLabels()
stickerNames.append(cell.stickerName)
cell.hasSticker = true;
//HERE MODIFY SPACING ---------------------------------------
//then for overflow just increase bottom inset?
//cell.center = CGPoint(x: cell.center.x, y: cell.center.y+100)
return cell
}
How can I do this? Why do I have just 1 section when I have 4 elements to go in the cells, and when I set the "number items in section" to 4 they all show up there?
What am I doing wrong?