How to reload programmatically moved row?

后端 未结 4 1241
别跟我提以往
别跟我提以往 2021-01-11 14:34

Frustrating fact: After calling tableView:moveRowAtIndexPath:toIndexPath:, tableView:cellForRowAtIndexPath: doesn\'t get called for that row.

4条回答
  •  甜味超标
    2021-01-11 14:43

    I do not think it is possible to do a move and a reload at the same time. I've tried several approaches and the best solution I've come up with is to do the reload just before the batch updates. I don't animate reloadRows because it seems to conflict with the batch update animations.

    [tableView reloadRowsAtIndexPaths:indexPathsToReload withRowAnimation:UITableViewRowAnimationNone];
    [tableView beginUpdates];
    //inserts, deletes and moves here
    [tableView endUpdates];
    

    Also, I typically put my cell configuration logic in a separate method like:

    - (void)tableView:(UITableView *)tableView configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
    

    So that I can just call it directly and bypass reloadRowsAtIndexPaths altogether. You won't get the built in animation this way either, but you can do your own animations.

提交回复
热议问题