daihovey
daihovey

Reputation: 3575

Deleting UITableCells programmatically without animation

When I programmatically delete a bunch of cells (I am normally at the bottom of the tableview) there is a move around of all the cells (as the ones being deleted are from the top). How can I stop this moving / jerking / rearranging when I delete them?

Upvotes: 0

Views: 689

Answers (3)

Angelo
Angelo

Reputation: 533

I think this is the method you're looking for (?) :

[tableView deleteRowsAtIndexPaths: indexPath withRowAnimation: UITableViewRowAnimationNone];

Upvotes: 3

Sid
Sid

Reputation: 9536

Before calling deleteRowsAtIndexPaths, save the indexPath of the row that is currently visible. Refer to this answer on how to do that.

Once you have the indexPath saved, after your rows are deleted, call this method:

[tableview scrollToRowAtIndexPath:savedIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

Upvotes: 1

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

use reloadData over adding and removing rows, and it'll all just snap.

Upvotes: 1

Related Questions