ios - 'NSInternalInconsistencyException',原因 : 'Requested the number of rows for section (0) which is out of bounds.'

标签 ios swift uitableview

当我尝试在 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)
    }

}

当我将变量行设置为它无一异常(exception)地加载的数字时,我认为 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()
    }
}

关于ios - 'NSInternalInconsistencyException',原因 : 'Requested the number of rows for section (0) which is out of bounds.' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61141561/

相关文章:

android - React Navigation - 在 Blurview 中包装标题和选项卡导航器会丢失 Prop

ios - React Native ios构建成功,但应用程序包的路径错误

iOS - 如何创建条纹图像?

swift - react swift : How to observe UIView isHidden?

ios - 如何知道tableView开始滚动

iphone - selectRowAtIndexPath 仅在 allowsMultipleSelection 为 YES 时有效

uitableview - UIViewController 中的 UISearchController

ios - 推送的自定义过渡和流行的标准过渡

ios - 从核心数据关系中删除对象 - NSSet

swift - Rxswift + Moya + Moya-ObjectMapper 错误处理