'NSInternalInconsistencyException', reason: 'Requested the number of rows for section (0) which is out of bounds.'

↘锁芯ラ 提交于 2021-02-08 08:48:21

问题


I'm getting this error when I try to run my app on iOS 13, older versions was working fine.

'NSInternalInconsistencyException', reason: 'Requested the number of rows for section (0) which is out of bounds.'

This is what I presume that is causing the exception

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)
    }

}

when I set the variable row to a number it loads without exception, I presume that an update on UITableView SDK caused it, I've tried searching google for some insights, but no success on this.


回答1:


Check for self.numberOfSections first. If there are no sections, then there can be no rows in that section (out of bounds).

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()
    }
}


来源:https://stackoverflow.com/questions/61141561/nsinternalinconsistencyexception-reason-requested-the-number-of-rows-for-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!