Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 852
Johannes Lund Avatar asked Dec 17 '12 19:12

Johannes Lund


3 Answers

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.

like image 111
Fostah Avatar answered Nov 08 '22 16:11

Fostah


This also works

[UIView performWithoutAnimation:^{
    [self.tableView insertRowsAtIndexPaths:indexPaths:withRowAnimation:UITableViewRowAnimationNone];
});
like image 32
Yinfeng Avatar answered Nov 08 '22 17:11

Yinfeng


Swift example (from my chat)

UIView.performWithoutAnimation {
        messagesTable.insertRows(at: [IndexPath(row: messages.count - 1, section: 0)], with: .none)
    }
like image 3
Евгений Коузов Avatar answered Nov 08 '22 16:11

Евгений Коузов