UITableView bouncing back to the top of a section when calling reloadRowsAtIndexPaths

后端 未结 9 1903
既然无缘
既然无缘 2020-12-15 03:14

When a user taps a button in one of my rows I am updating the underlying model for that row and then calling reloadRowsAtIndexPaths for the given row (i.e. single row reload

相关标签:
9条回答
  • 2020-12-15 04:11

    Swift 4.2

    This can work anywhere you want to remove animation. During reload of table , table section or any row

     UIView.performWithoutAnimation({
                    cell.configureSelection(isSelected: true)
                    tableView.reloadSections([1], with: .none)
                    tableView.allowsSelection =  false
    
                })
    
    0 讨论(0)
  • 2020-12-15 04:11

    It may be possible to put the cell in it's own section and call reload section:

    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
    

    this appears to fix the issue partially. Not the cleanest way but it may work for you.

    0 讨论(0)
  • 2020-12-15 04:12

    Ah Ha! I found the problem and am going to answer my own question for the poor soul who runs into this issue in the future.

    All of my cells have variable height so I was using the new iOS7 method in UITableViewDelegate thinking it might speed up render time (not that I really needed it):

    - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath;
    

    Anyway, implementing this method has the evil side effect of causing the table to bounce to the top of the section when calling:

    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    

    To solve the bounce problem I just removed the override of that estimatedHeightForRowAtIndexPath method and now everything works as it should. Happy at last.

    0 讨论(0)
提交回复
热议问题