Header Section not displaying in collection view programatically

402 views Asked by At

Here is the code that i have

import UIKit

class UserProfileController : UICollectionViewController, UICollectionViewDelegateFlowLayout{

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView?.backgroundColor = .white

        //NEED TO UPDATE: GET USERNAME TO AND SET NAVTITLE
        fetchUser()

        //UPDATE ALL USER PAGE INFO IN

        collectionView?.register(UICollectionViewCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "headerId")
    }

    fileprivate func fetchUser(){
        //Assumed loged in get user ID
        //guard let uid = currentUser?.uid else {return}

        //NEED TO UPDATE: GET USERNAME FROM USER ID HASH
        let username = "User Profile"
        navigationItem.title = username
    }

    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "headerId", for: indexPath)

        header.backgroundColor = .green

        return header
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        return CGSize(width: view.frame.width, height: 200)
    }
}

This all looks ok to me, I'm not sure what it is that is wrong here.

1

There are 1 answers

5
picciano On

There doesn't seem to be anything wring with your code as posted. Perhaps an issue in your story board?

enter image description here