reloadRowsAtIndexPaths:withRowAnimation: crashes my app

后端 未结 8 1980
谎友^
谎友^ 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:00

    The app crashes because you have made some changes to your tableView. Either you have added or deleted some rows to the tableView. Hence when the view controller asks your model controller class for data, there is a mismatch in the indexPaths. Since the indexPaths have changed after modification.

    So either you simply remove the call

    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
    

    or replace it with

    [self.tableView reloadData];
    

    Calling reloadData checks your number of sections, number of rows in each section and then reloads the whole thing.

提交回复
热议问题