另一个 SIGABRT 错误

Another SIGABRT error

我在下面的行中收到错误 Thread1: signal SIGABRT,我已经尝试过:

另外查看此论坛中的许多帖子。

之后我删除了所有与故事板的连接并再次连接但仍然出现相同的错误:(

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell2 = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as! DefinitionTableViewCell

在控制台中:

Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-3347.44/UITableView.m:6245

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier cell2 - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

非常欢迎任何帮助 Tks :)

好吧,正如异常消息所暗示的那样,您 "must register a nib or a class for the identifier"。尝试在 viewDidLoad() 中添加此行:

tableView.registerNib(UINib(nibName: "nameOfYourCustomNib", bundle: nil), forCellReuseIdentifier: "cell2")

nameOfYourCustomNib 替换为您的 nib 名称,例如,如果您有一个文件 MyCustomCell.xib 那么该名称将是 MyCustomCell.

如果失败,尝试注册 class 而不是 nib(记得删除第一行),输入:

tableView.registerClass(DefinitionTableViewCell.self, forCellReuseIdentifier: "cell2")  

最重要的是,在 cellForRowAtIndexPath 中,确保检查单元格是否为 nil,如果是,则创建一个新的 DefinitionTableViewCell