ios - 'NSInternalInconsistencyException',原因:'请求节 (0) 的行数超出范围。
问题描述
当我尝试在 iOS 13 上运行我的应用程序时出现此错误,旧版本运行良好。
'NSInternalInconsistencyException', reason: 'Requested the number of rows for section (0) which is out of bounds.'
这就是我认为导致异常的原因
override func reloadData() {
super.reloadData()
let rows = self.numberOfRows(inSection: 0) // what I know is that this line is causing the exception
if (rows > 0) {
if placeholderStackView != nil {
self.placeholderStackView.removeFromSuperview()
}
} else {
setTableStatus(type: .empty)
}
}
当我将变量行设置为它无一例外地加载的数字时,我认为 UITableView SDK 的更新导致了它,我尝试在谷歌搜索一些见解,但没有成功。
解决方案
先检查一下self.numberOfSections
。如果没有部分,则该部分中不能有行(超出范围)。
override func reloadData() {
super.reloadData()
guard 0 < self.numberOfSections && 0 < self.numberOfRows(inSection: 0) else {
setTableStatus(type: .empty)
return
}
if placeholderStackView != nil {
self.placeholderStackView.removeFromSuperview()
}
}
推荐阅读
- bootstrap-4 - 如何使用 Col 显示引导卡列表?
- amazon-web-services - VPC 对等互连之间的 CIDR 范围重叠 - AWS
- php - 在模板部分的页面顶部显示图像以循环显示帖子
- ruby-on-rails - 我们如何在本地调试 ruby AWS lambda 函数?
- r - R:分组索引的行
- arrays - 简化二维网格上的路径
- javascript - 如何在 Discord.js 中收集 DM 中的用户消息
- swift - 如何将我的自定义标签粘贴到每部 Iphone 的底部(有和没有 SafeArea)?
- java - IBM Semeru 和 Adoptium 有什么区别
- lua - 我想将 `variable..'['..i..']'` 视为索引尝试