Can´t add items to UICollectionView inside UIView xib

后端 未结 5 1764
说谎
说谎 2021-02-05 09:20

Objective

I wanna place my (BusinessViewTableHeader: UIView) as tableView header:

tableView.tableHeaderView = BusinessViewTableHeader.instanceFromNib() a         


        
5条回答
  •  清酒与你
    2021-02-05 09:35

    You can't have UICollectionViewCell when the UICollectionView is on a Nib. What you need to do is to create the UICollectionViewCell as another nib and get it registered in the class that you are using for your CollectionView.

    Create a new nib, drag a UICollectionViewCell inside it, and do something like this in the class that works with your UICollectionView.

    override func awakeFromNib() {
        let nibName = UINib(nibName: "ClassCollectionCell", bundle:nil)
        collectionView.registerNib(nibName, forCellWithReuseIdentifier: "collectionCell")
    }
    

    Remember you can add a custom class to the UICollectionViewCell so you can pass dynamic data to it.

提交回复
热议问题