这是我拥有的代码
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)
}
}
这一切对我来说都很好,我不确定这里有什么问题。