Ios Can';无法在swift 4中的UIcollectionView页面上显示标题

Ios Can';无法在swift 4中的UIcollectionView页面上显示标题,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我正在尝试创建一个类似instagram的配置文件页面,但无法在我的UICollectionView(UserProfileVC.swift)页面上显示我的标题(UserProfileHeader.swift) 我试图通过在每个代码块中添加打印语句来调试代码,如下面附加的快照所示,当我转到模拟器上的配置文件页面时,唯一打印到控制台中的语句是numberOfSections和numberOfItemsInSection函数中的语句,我不知道这是应该发生的还是其他功能没有被访问。我做错了什么 imp

我正在尝试创建一个类似instagram的配置文件页面,但无法在我的UICollectionView(UserProfileVC.swift)页面上显示我的标题(UserProfileHeader.swift)

我试图通过在每个代码块中添加打印语句来调试代码,如下面附加的快照所示,当我转到模拟器上的配置文件页面时,唯一打印到控制台中的语句是numberOfSections和numberOfItemsInSection函数中的语句,我不知道这是应该发生的还是其他功能没有被访问。我做错了什么

import UIKit
import Firebase

private let reuseIdentifier = "Cell"
private let headerIdentifier = "UserProfileHeader"

class UserProfileVC: UICollectionViewController, UICollectionViewDelegateFlowLayout {

    // MARK: Properties

    let db = Firestore.firestore() // Connects firestore

    let customGrayColor = UIColor(red: 247/255, green: 247/255, blue: 242/255, alpha: 1)

    override func viewDidLoad() {
        super.viewDidLoad()

        let settings = db.settings
        settings.areTimestampsInSnapshotsEnabled = true
        db.settings = settings

        // Register cell classes
        self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

        self.collectionView!.register(UserProfileHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)


        // Background color
        self.collectionView?.backgroundColor = customGrayColor

        fetchCurrentUserData()
    }


    // MARK: UICollectionView

    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        print("numberOfSections works -------------------->")
        return 1
    }


    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of items
        print("numberOfItemsInSection -------------------->")
        return 0
    }


    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        print("referenceSizeForHeaderInSection -------------------->")

        return CGSize(width: view.frame.width, height: 200)
    }


    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

        // Declare header
        let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath) as! UserProfileHeader
        print("dequeueReusableSupplementaryView -------------------->")

        // Return header
        return header
    }


    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)

        // Configure the cell
        print("dequeueReusableCell -------------------->")
        return cell
        }
}
UserProfileHeader.swift脚本

import UIKit

class UserProfileHeader: UICollectionViewCell {

    override init(frame: CGRect) {
        super.init(frame: frame)

        self.backgroundColor = .red

        print("UserProfileHeader -------------------->")


    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
控制台

    nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x7faa496143b0] get output frames failed, state 8196
2019-03-15 09:59:29.118574-0500 HobbiStyle[35259:1722282] [BoringSSL] 
    nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x7faa496143b0] get output frames failed, state 8196
2019-03-15 09:59:29.119123-0500 HobbiStyle[35259:1722282] TIC Read Status [1:0x0]: 1:57
2019-03-15 09:59:29.119274-0500 HobbiStyle[35259:1722282] TIC Read Status [1:0x0]: 1:57
numberOfSections works -------------------->
numberOfItemsInSection -------------------->

我发现了问题,两个脚本都很好,问题出在我的选项卡栏控制器上,我将profileVC声明为UICollectionViewLayout而不是UICollectionViewFlowLayout。要归功于@StephanDowless

我发现了问题,两个脚本都很好,问题出在我的选项卡栏控制器上,我将profileVC声明为UICollectionViewLayout,而不是UICollectionViewFlowLayout。要归功于@StephanDowless

你说的话毫无意义。如何从“无法在我的UIcollectionView上显示我的标题”变为UICollectionViewCell的子类化?如果需要,为什么不使用UIView创建一个页眉或页脚视图呢?你所说的没有意义。如何从“无法在我的UIcollectionView上显示我的标题”变为UICollectionViewCell的子类化?如果需要,为什么不使用UIView创建页眉或页脚视图呢?