ios - 无法将单元格转换为自定义单元格
问题描述
我制作了一个自定义单元格,但它没有被调用或强制转换。
我尝试了不同的方法来调用标识符,注册单元格,但没有任何效果,我有一个示例项目,它正在工作,我有它完全相同。所以我不知道是什么原因造成的。
目前这些是我的功能。调试,我发现它从来没有进入过里面的if条件,cellForRowAt
所以这就是问题所在,但无法弄清楚是什么原因造成的。
func registerCell() {
let cellNib = UINib(nibName: FAQTableViewCell.reuseIdentifier, bundle: nil)
tableView.register(cellNib, forCellReuseIdentifier: FAQTableViewCell.reuseIdentifier)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: FAQTableViewCell.reuseIdentifier, for: indexPath)
if let cell = cell as? FAQTableViewCell {
cell.preguntaLabel.text = arrayTitulo[indexPath.row] as? String
cell.respuestaLabel.text = arrayDesc[indexPath.row] as? String
}
return cell
}
我检查了所有内容,单元格的 .xib、cell.swift 和 controller.swift,所有内容都匹配。我不知道还能做什么。
FAQTableViewCell
:
import AEAccordion
final class FAQTableViewCell: AccordionTableViewCell {
static let reuseIdentifier = "FAQTableViewCell"
@IBOutlet weak var headerView: UIView!
@IBOutlet weak var detailView: UIView!
@IBOutlet weak var preguntaLabel: UILabel!
@IBOutlet weak var respuestaLabel: UILabel!
// MARK: Override
override func setExpanded(_ expanded: Bool, animated: Bool) {
super.setExpanded(expanded, animated: animated)
if animated {
UIView.transition(with: detailView, duration: 0.3, animations: {
self.detailView.isHidden = !expanded
}, completion: nil)
} else {
detailView.isHidden = !expanded
}
}
private func toggleCell() {
detailView.isHidden = !expanded
}
}
已修复:我刚刚删除了 .xib 并在 Main.storyboard 的 TableViewController 中创建了自定义单元格
解决方案
我有同样的问题。在 Identity Inspector 中,Custom Class Inherit Module from Target 下方没有被选中,再次检查后,它被完美地转换了。
推荐阅读
- google-cloud-platform - Web GCloud 无法连接,SDK 可达性失败,Bash 命令不可用
- maven - Spring boot 2.0 neo4j ogm 3.0 兼容jetty版
- pointers - CoDeSys 指针引用大小
- reactjs - 立即对 setstate 做出反应并重新渲染
- fontforge - 如何创建包含 5 个以上元素的连字?
- ag-grid - 带有 agGrid 单元格渲染器的上下文 API
- ios - 使用 NSTextAttachment 在粘贴板中存储和检索 NSAttributed 字符串
- php - 如何显示不同大小的动态加载图像?
- angular - 如何仅以角度第一次从服务器获取数据?
- java - 对象变量与 setter 和 getter