0

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.

zimmerrol
  • 4,872
  • 3
  • 22
  • 41
NojDavid
  • 89
  • 1
  • 10
  • Did you override a `numberOfSections` function of `UICollectionViewDataSource`? Have you implemented this protocol at all? Because you won't see anything unless giving the collection view some data. – Vadim Popov Dec 15 '17 at 20:28
  • I override this function and nothing happens – NojDavid Dec 15 '17 at 21:19

1 Answers1

0

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

enter image description here

picciano
  • 22,341
  • 9
  • 69
  • 82
  • i do get a warning, i used to use main.storyboard but then i switched to doing everything programmatically, so the story board is empty and every-time i run i get : Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set? – NojDavid Dec 15 '17 at 21:00
  • I can see the collection view, if i set its background to red, the screen is red so i know its there, but the header will not show – NojDavid Dec 15 '17 at 21:08
  • How did you get it to display? I recreated my project to test this out and still couldnt get it to come up. DId you change anything when you made it??? – NojDavid Dec 15 '17 at 21:27
  • I copy/pasted your code verbatim. I started with a new project, created a navigation controller in the storyboard and a collection view controller as it's root view controller. I set the class of the new collection view controller to "ViewController" and pasted your code into that class. No additional methods or code. – picciano Dec 16 '17 at 00:56
  • Whatever the issue is, it's not in the code your put into the question. – picciano Dec 16 '17 at 01:09