Johannes Lund
Johannes Lund

Reputation: 1917

Insert UITableView row without ANY animation

[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] 
                      withRowAnimation:UITableViewRowAnimationNone];

When doing this every row after the one I'm inserting slides down. I want them to immediately jump to their new place. I don't want to call reloadData since then all my cells would be redrawn.

Is it possible to remove this animation?

Upvotes: 21

Views: 11810

Answers (5)

barche
barche

Reputation: 319

Swift example (from my chat)

UIView.performWithoutAnimation {
        messagesTable.insertRows(at: [IndexPath(row: messages.count - 1, section: 0)], with: .none)
    }

Upvotes: 3

Yinfeng
Yinfeng

Reputation: 5211

This also works

[UIView performWithoutAnimation:^{
    [self.tableView insertRowsAtIndexPaths:indexPaths:withRowAnimation:UITableViewRowAnimationNone];
});

Upvotes: 15

Fostah
Fostah

Reputation: 11776

This works for me:

[UIView setAnimationsEnabled:NO];
[self.tableView beginUpdates];

[self.tableView insertRowsAtIndexPaths:indexPath
                      withRowAnimation:UITableViewRowAnimationNone];

[self.tableView endUpdates];
[UIView setAnimationsEnabled:YES];

Hope this helps.

Upvotes: 51

colincameron
colincameron

Reputation: 2704

If you update the UITableView's dataSource and call [tableView reloadData] instead of manually inserting the row, the table will refresh without any animation.

Upvotes: 0

Brandon Brodjeski
Brandon Brodjeski

Reputation: 400

Unfortunately, I ran into this same issue and there was no way for me to remove the animation.

Must be a bug with the UITableViewRowAnimationNone animation type since iOS (of any version) does not seem to respect it.

Upvotes: 0

Related Questions