无法使标识符为“costumeCell”的单元出列 - 必须为标识符注册笔尖或类,或者连接情节提要中的原型单元

nsl*_*ava 1 uitableview ios swift

我正在尝试创建一个简单的应用程序,但是:

'NSInternalInconsistencyException',原因:'无法使具有标识符术语的单元出列 - 必须为标识符注册笔尖或类,或者连接情节提要中的原型单元'

代码:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CostumeCellView

    cell.textLabel?.text = titles[indexPath.row]

    return cell
}
Run Code Online (Sandbox Code Playgroud)

屏幕:

班级

标识符

我不知道该怎么做。

Rya*_*los 5

您可能需要注册您的手机。它看起来像这样。

如果您在代码中使用单元类:

tableView.register(MyTableViewCell.self, forCellReuseIdentifier: "Cell")
Run Code Online (Sandbox Code Playgroud)

如果您使用带笔尖的单元格:

let nib = UINib(nibName: "MyTableViewCellNibFile", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "Cell")
Run Code Online (Sandbox Code Playgroud)

如果您使用故事板,则需要确保原型单元设置正确。这个答案实际上已经很好地定义了/sf/answers/1045790231/

https://developer.apple.com/reference/uikit/uitableview/1614937-register