swift - 自定义单元格导致“NSInternalInconsistencyException”,原因:“无法在包中加载 NIB:
问题描述
我正在尝试使用 XIB 文件将自定义单元格添加到我的表中,当我尝试运行它时出现此错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'parentCell''
这些是我为到达这里所采取的步骤:
1) 创建自定义 xib 故事板单元格 2) 将故事板单元格的标识符设置为 parentCell 3) 为自定义 xib 创建一个类为 ParentTableViewCell 4) 将 xib 故事板单元格的类设置为 ParentTableViewCell 5) 在主情节提要,并在主 ViewController 中为名为 itemsTable 的表制作了一个 IBOutlet。6)在主ViewController的viewdidload中设置:
itemsTable.dataSource = self
itemsTable.delegate = self
itemsTable.register(UINib(nibName: "parentCell", bundle: nil), forCellReuseIdentifier: "parentCell")
7) 在 cellForRowAt 中:
let cell = tableView.dequeueReusableCell(withIdentifier: "parentCell", for: indexPath) as! ParentTableViewCell
return cell
你们能看看我是否错过了导致问题的步骤吗?
我试过 command + shift + k 并显示相同的错误。
解决方案
如果 xib 名称是ParentTableViewCell.xib
那么你应该做
itemsTable.register(UINib(nibName: "ParentTableViewCell", bundle: nil), forCellReuseIdentifier: "parentCell")
推荐阅读
- css - Gmail 中的基础电子邮件错误
- bash - 任何工具可以并行化具有不同 CPU 要求的 bash 命令?
- python - 如何在python数据框中将对象数据类型转换为浮点数
- javascript - 通过 API 中的 req.query 将元数据信息附加到 Gridfs 文档文件 - Node.js Expresss.js MongoDB Multer Gridfs 流
- symfony - Symfony3.4 / Doctrine:FROM 子句中的子查询:错误:未定义“SELECT”类
- android - Retrofit 中这个 URL 的接口是什么
- php - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册
- c# - 如何在列表视图中添加新标签
- php - 在 Woocommerce 我的帐户查看订单页面中为自定义状态启用“重新排序”按钮
- ios - 如何找到 iOS 设备的辅助功能大小