【发布时间】:2018-07-18 09:50:49
【问题描述】:
我有两个带有两个不同自定义表格视图单元格的表格视图。我正在这样做:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == self.tableview {
let cell = tableview.dequeueReusableCell(withIdentifier: "matchescell") as! MatchesTableViewCell
// ......
return cell
} else {
let cell = tableview.dequeueReusableCell(withIdentifier: "filtercell") as! FilterTableViewCell
// ......
return cell
}
}
当然,我已经从情节提要中注册了它们......
但我不断得到这个:
在这一行:
let cell = tableview.dequeueReusableCell(withIdentifier: "filtercell") as!过滤表视图单元格
尝试像这样注册它们:
tableview.register(MatchesTableViewCell.self, forCellReuseIdentifier: "matchescell")
filterdrop.register(FilterTableViewCell.self, forCellReuseIdentifier: "filtercell")
但仍然出现同样的错误!
做错了什么?!
【问题讨论】:
-
控制台中的完整错误信息是什么?你错过了一步。但这可能是因为您没有注册类,您没有注册 xib(如果它在自定义 xib 中),您没有在单元格属性中设置正确的类/标识符等。
-
@Larme 我做到了!并仔细检查! :(
-
向我们展示您注册 xib 的行
-
@Nitish 刚刚更新了我的问题
-
检查我的答案,你只是输入错误。