【发布时间】:2018-02-01 19:47:19
【问题描述】:
当我尝试打开表格视图时,我在控制台中收到此错误:
“无法将 'UITableViewCell' 类型的值转换为 'AppName.NameTableViewCell'。”
值得注意的几点:
- 我没有使用故事板
- 我已经在 viewDidLoad() 中将单元格注册到 tableView 中
这里有一些截图来澄清一下。
let tableView = UITableView()
override func viewDidLoad() {
tableView.register(NameTableViewCell.self, forCellReuseIdentifier: "cellName")
...
}
...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = UITableViewCell(style: .default, reuseIdentifier: "cellName") as! NameTableViewCell
cell.textCell.text = self.menuText[indexPath.row]
return cell
}
}
【问题讨论】:
-
请勿张贴代码图片。 Edit您的问题并将图片替换为您的实际代码,作为文本。
-
看,你的主要问题在于转换,使用一个或多个单元格并不重要,你应该将单元格出列而不是将常规的 tableview 单元格投射到自定义单元格
标签: ios swift uitableview