Alan
Alan

Reputation: 9481

UITableView reloadSection and reloadRowsAtIndexPaths causes weird animation

I am doing lazy loading for my UITableView so I am trying to reload individual rows as the images get updated. I am however running into a strange problem.

When I call,

    [self.bubbleTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];

OR

    [self.bubbleTableView reloadSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationNone];

When I specifically say No Animation it still animates and the animation is the Image taking up the entire cell and shrinking rapidly into the normal size. Also, if I change it to any other animation, it does the same animation no matter what setting.

If I comment either one of those out and just use reloadData it works fine, but I'd rather not do reloadData for performance reasons of reupdating cells that don't need updating.

Thanks!

Upvotes: 20

Views: 12482

Answers (4)

ad1Dima
ad1Dima

Reputation: 3207

Here was an answer

[UIView setAnimationsEnabled:NO];
[self.bubbleTableView reloadSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationNone];
[UIView setAnimationsEnabled:YES];

It works for me.

UPD. Same with block by @Şafak-gezer

[UIView performWithoutAnimation:^{
    [self.bubbleTableView reloadSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationNone];
}];

SWIFT

UIView.performWithoutAnimation {
            self.bubbleTableView.reloadSections(NSIndexSet(index: indexPath.section), withRowAnimation: UITableViewRowAnimation.None)
        }

Upvotes: 48

Şafak Gezer
Şafak Gezer

Reputation: 4007

Below method worked for me: (for iOS 7 and better)

[UIView performWithoutAnimation:^{
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationNone];
}];

Upvotes: 8

just.jimmy
just.jimmy

Reputation: 954

I found this happening to me on the iOS Simulator. After a few reloads it worked normally with no animation. Could be just a bug in the simulator.

Upvotes: -3

Markus
Markus

Reputation: 538

Use cellForRowAtIndexPath: to only update the cell you are interested in.

Upvotes: 0

Related Questions