繁体   English   中英

'NSInternalInconsistencyExceptionException'原因:将表视图单元出队时,“无法在捆绑包中装载NIB”

[英]'NSInternalInconsistencyException' reason: 'Could not load NIB in bundle' when dequeuing tableview cell

我不知道为什么会收到此错误,并且我尝试查看其他答案,但找不到解决方案。

有问题的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    messagesTableView?.register(UINib.init(nibName: "messageTableViewCell", bundle: nil), forCellReuseIdentifier: "messageTableViewCell")

    messagesTableView.delegate = self;
    messagesTableView.dataSource = self;
    dataSrc.delegate = self


}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


    if let cell = tableView.dequeueReusableCell(withIdentifier: "messageTableViewCell", for: indexPath) as? MessagesTableViewCell {

        cell.configureWithItem(item: dataArray[indexPath.item])

        return cell
    }
    return UITableViewCell()
}

调用tableView.dequeueReusableCell时出现错误。 我还确保将单元格的标识符设置为“ messageTableViewCell”

请确保已创建一个名为MessageTableViewCellnib/xib文件,然后注册该nib文件MessageTableViewCell

let nib = UINib(nibName: "MessageTableViewCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "messageTableViewCell")

初始化UINib ,必须将文件名作为nibName参数传递

在此处输入图片说明

UINib(nibName: "TableViewCell", bundle: nil)

所以在您的情况下,我想您的文件的名称与您的类MessagesTableViewCell相同

messagesTableView?.register(UINib(nibName: "MessagesTableViewCell", bundle: nil), forCellReuseIdentifier: "messageTableViewCell")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM