Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Corotata opened this issue Aug 23, 2021 · 0 comments
Open

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

Corotata opened this issue Aug 23, 2021 · 0 comments

Comments

@Corotata
Copy link

Corotata commented Aug 23, 2021

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
    }
}
@Corotata Corotata changed the title If I register collectionViewCell by code, Is it not allowed to use code to register collectionViewCell ? Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant