ios - 如何以编程方式子类化 CollectionViewCell 并更改子类标识符?

标签 ios swift uikit

我有带有 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/

相关文章:

iphone - 在 iphone 的缩略图中显示视频时长

iOS : What is the need of register cell before dequeuing in UITableView?

swift - 将 cookie 传递给 WKWebView/SFSafariViewController?

ios - UITextView 由于行数和字符数限制文本

objective-c - 如何自定义 UIWebView 点按链接表

ios - Swift 和 UIKit 中的曲线动画 - 从起点/终点开始的抛物线运动

ios - WKWebView 如何在 WKNavigationDelegate 方法中找到请求

ios - Swift 排名字典

ios - Tableview 拖到底部时导致应用程序崩溃

android - PhoneGap 忽略设置了特定宽度的视口(viewport)标签?