[英]'NSInternalInconsistencyException' reason: 'Could not load NIB in bundle' when dequeuing tableview cell
I have no clue why I am getting this error and I have tried looking at other answers, but could not find a solution. 我不知道为什么会收到此错误,并且我尝试查看其他答案,但找不到解决方案。
The code in question: 有问题的代码:
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()
}
When tableView.dequeueReusableCell is called I get the error. 调用tableView.dequeueReusableCell时出现错误。 I have also made sure the identifier for the cell is set to "messageTableViewCell"
我还确保将单元格的标识符设置为“ messageTableViewCell”
Please make sure you have created a nib/xib
file named as MessageTableViewCell
, then register the nib file MessageTableViewCell
, 请确保已创建一个名为
MessageTableViewCell
的nib/xib
文件,然后注册该nib文件MessageTableViewCell
,
let nib = UINib(nibName: "MessageTableViewCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "messageTableViewCell")
When you're initializing UINib
, as nibName
parameter you have to pass name of the file 初始化
UINib
,必须将文件名作为nibName
参数传递
UINib(nibName: "TableViewCell", bundle: nil)
so in your case I suppose your file is named same as your class MessagesTableViewCell
所以在您的情况下,我想您的文件的名称与您的类
MessagesTableViewCell
相同
messagesTableView?.register(UINib(nibName: "MessagesTableViewCell", bundle: nil), forCellReuseIdentifier: "messageTableViewCell")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.