ios - 为什么我不能将此单元格快速转换为从单元格继承的类?
问题描述
我正在TableView
使用我在其他几个应用程序中完成的 swift创建一个UITableViewCOntroller
,但是这次当我尝试将我的单元格转换为自定义单元格类时,我收到无法转换的错误。
这是我的代码:
class CollapseNoteViewController: UITableViewController {
let titleArray = ["Troy and Abed", "Shirly and Annie", "Pierce and Ben"]
let noteArray = ["The best", "Pretty cool", "The worst"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titleArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// This is where I get the error
let cell = tableView.dequeueReusableCell(withIdentifier: K.reuseIdentifier, for: indexPath) as! NoteTableViewCell
cell.titleLabel?.text = titleArray[indexPath.row]
cell.textLabel?.text = noteArray[indexPath.row]
return cell
}
}
class NoteTableViewCell: UITableViewCell {
@IBOutlet weak var cardView: UIView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var mainTextLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
}
完整的错误文本:
Could not cast value of type 'UITableViewCell' (0x1eccdbb70) to 'CollapseANote.NoteTableViewCell' (0x104d3ced8).
Could not cast value of type 'UITableViewCell' (0x1eccdbb70) to 'CollapseANote.NoteTableViewCell' (0x104d3ced8).
2021-02-18 10:36:47.613801-0500 CollapseANote[639:74162] Could not cast value of type 'UITableViewCell' (0x1eccdbb70) to 'CollapseANote.NoteTableViewCell' (0x104d3ced8).
我在哪里设置原型单元的类:
我在哪里设置课程TableViewController
:
解决方案
推荐阅读
- graphql - GraphQL 突变问题
- scala - 如何在 Scala 中区分 SortedMap 和 TreeMap?
- asp.net-core-mvc - 有条件地处理 ASP.NET Core 中的拒绝访问行为
- javascript - 如何始终在单击的元素下方打开 contextMenu?
- javascript - 无法在谷歌表单中设置依赖下拉
- ios - Xamarin iOS 在 UIButton 中显示图像和文本
- c# - 为什么在运行时调用重载函数时会发生 RuntimeBinderException?
- android - Android 应用程序 Api 1 与 Api 2 中的 Google Pay
- java - Junit 测试用例 - 错误 - 预期状态:<200> 但原为:<500>
- c# - C# Winforms:当用户选择(鼠标单击)图表上的一个点时如何获取值