reloadRowsAtIndexPaths:withRowAnimation: crashes my app

后端 未结 8 1993
谎友^
谎友^ 2021-02-07 01:33

I got a strange problem with my UITableView: I use reloadRowsAtIndexPaths:withRowAnimation: to reload some specific rows, but the app crashes with an seemingly unre

相关标签:
8条回答
  • 2021-02-07 02:01

    I had the same issue. In my case; it was happening only if another view controller pop/pushed over existing table view controller and then[self.tableView reloadRowsAtIndexPaths] function is called.

    reloadRowsAtIndexPaths call was hiding/showing different rows in a table view which is having over 30, visually complex, rows. As i try to fix the issue i found that if i slightly scroll the table view app wasn't crashing. Also it wasn't crashing if i don't hide a cell (by returning 0 as height)

    To resolve the issue, i simply changed the "(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath" function and returned at least 0.01 as row height.

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    ....
    return rowModel.height + 0.01; // Add 0.01 to work around the crash issue.
    }
    

    it solved the issue for me.

    0 讨论(0)
  • 2021-02-07 02:07

    You should check cell visibility before reload. Here is Swift 3 code:

            let indexPath = IndexPath(row: offset, section: 0)
            let isVisible = tableView.indexPathsForVisibleRows?.contains{$0 == indexPath}
            if let v = isVisible, v == true {
                tableView.reloadRows(at: [indexPath], with: .automatic)
            }
    
    0 讨论(0)
提交回复
热议问题