2
votes

I have a UITableview with section and index title. When user click on a cell a option view of height 42 gets display in that cell. To display that option I reload the cell. But section header is also getting updated. That gives bizarre animation. How to reload only cell,without getting called for other delegate method like heightForHeaderInSection and viewForHeaderInSection.

3
What code have you written to reload the tableview. And what exactly you want to do. You want to reload only cell or Section?Vatsal K
use begin/endupdate to reload cellEI Captain v2.0

3 Answers

2
votes

I think you should only update the particular row for indexPath, try the code below

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    [tableView beginUpdates];
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    [tableView endUpdates];

}

It might help you.

Cheers.

2
votes

In Swift 2.0 & above

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        tableView.beginUpdates() 
        tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
        tableView.endUpdates()

       }
2
votes

There are several methods for reloading the tableview.

  1. To reload whole section including section's cell.

    - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation

Example:

[tableVIewContent reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic];
  1. To reload single/multiple cells

    - (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath > )indexPaths withRowAnimation:(UITableViewRowAnimation)animation

Example:

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
  1. To reload whole tableview.

    - (void)reloadData;

    // reloads everything from scratch. redisplays visible rows. because we only keep info about visible rows, this is cheap. will adjust offset if table shrinks