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

后端 未结 9 1929
既然无缘
既然无缘 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:05

    You should be able to do what you are trying to do by changing the cell contents directly. For example, if you are using the base UITableViewCell class and the data in your model is a NSString which you show in the table view cell, you can do the following (after you change your data model) instead of calling reloadRowsAtIndexPaths:

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    UILabel *label = [cell textLabel];
    label.text = @"New Value";
    

    If you are using a custom subclass of UITableViewCell, it's roughly the same except for accessing the views of the cell will need to be done through the contentView property.

提交回复
热议问题