我有带有 Nib 文件的 collectionViewCell
ACollectionViewCell
ACollectionViewCell.xib
在我的 ACollectionViewCell 中,我从 .xib 中删除了 @IBOutlet 。
我创建一个名为 BCollectionViewCell 的新子类</p>
class BCollectionViewCell : ACollectionViewCell { ... }
我想在 CollectionViewController 中使用 ACell 和 BCell
collectionView.dequeueReusableCell(withReuseIdentifier:"ACollectionViewCell ") .....
问题就在这里,BCollectionViewCell没有.xib,无法设置ReuseIdentifier
如何在不创建新的 BCell.xib 的情况下设置我的 BCollectionViewCell Reuseidentifier ???
最佳答案
您可以在没有 xib 的情况下注册单元格
collectionView.register(BCollectionViewCell.self, forCellWithReuseIdentifier: "BCollectionViewCell ")
但它应该完全以编程方式创建,因此对于您的情况,我建议以编程方式创建 ACollectionViewCell
,因为当您访问内部主类 ACollectionViewCell
的 ultets 时,您可能会遇到零异常BCollectionViewCell
关于ios - 如何以编程方式子类化 CollectionViewCell 并更改子类标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54844540/