Skip to content

Is it not allowed to use code to register collectionViewCell ? #86

Description

@Corotata

If I register collectionViewCell in storyboard,it work well, but when I use a xib to create viewController,register collectionViewCell by code,it crash.

613C7D8C-F476-40A1-B6DC-A07F08E275B4

@IBDesignable
class EnterpriseUserCardCollectionViewCell: NibCollectionViewCell {
    override  func awakeFromNib() {
        super.awakeFromNib()
        self.contentView.layer.cornerRadius = 8
        self.contentView.clipsToBounds = true
    }
}

class TestCollectionViewController: UIViewController,UICollectionViewDataSource {
    @IBOutlet weak var collectionView: UICollectionView!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.collectionView.dataSource = self
        self.collectionView.register(UINib(nibName: "EnterpriseUserCardCollectionViewCell", bundle: .main), forCellWithReuseIdentifier: "EnterpriseUserCardCollectionViewCell")
    }
    
     func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }


     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }

     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "EnterpriseUserCardCollectionViewCell", for: indexPath)
        return cell
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions