UITableViewRowAnimation is ignored

I am using NSFetchedResultsController to populate my table. The data in my table is sorted according to the timestamp in ascending order (last message below). Additional data is loaded using the "infinite scroll" at the top: for example. when the user scrolls from the top, more messages are loaded. My NSFetchedResultsControllerDelegate defined as usual, as recommended in the apple documentation: new lines are inserted through

 - (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath { switch(type) { case NSFetchedResultsChangeInsert: NSLog(@"insertion at row %d", newIndexPath.row); [self.table insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone]; break; 

Now here is my problem: when new lines are inserted, they are always animated as sliding “down”. On endless scrolling up, it looks bad. This happens whether I pass UITableViewRowAnimationNone , UITableViewRowAnimationTop or UITableViewRowAnimationBottom as a parameter - this parameter seems to be completely ignored.

Any ideas on how to animate the table correctly?

+4
source share
5 answers

So, I figured it out.

A discussion of WWDC 2011 "Advanced table viewing methods" clearly indicates that UITableViewRowAnimationNone does not mean the lack of animation (:

As if that made sense.

The animation parameter simply determines how the line is inserted into the space (for example, a slide on the right / left / etc.), the transitions to create this space are animated regardless of what the user wants.

So, there is no way to insert / delete / update individual cells, and reloadData is the way to go. I love you, Apple.

Now, according to numerous answers to stackoverflow, there is also no way to insert content at the top of the table without changing the current view (for example, without inserting material without making any changes to what the user sees). The best thing you can do is change the contentOffset after the new data has appeared.

+10
source

Try as shown below.

 [CATransaction setDisableActions:YES]; [self.table insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone]; [CATransaction setDisableActions:NO]; // reset to original value 
+13
source

I found a way to disable the insert / delete cell animation.

  [UIView setAnimationsEnabled:NO]; [_tableView beginUpdates]; [_table insertCell...]; [_table removeCell...] [_table endUpdates]; [UIView setAnimationsEnabled:YES]; 

This works great.

+6
source

As in iOS 7.0, you can wrap the code in a block performWithoutAnimation: for example:

 [UIView performWithoutAnimation:^{ [self.tableView beginUpdates]; [self.tableView deleteRowsAtIndexPaths:rowsToRemove withRowAnimation:UITableViewRowAnimationNone]; [self.tableView endUpdates]; }]; 
+4
source

Do you partition data? If so, check your implementation of controller:didChangeSection:atIndex:forChangeType: as the new section inserts will be animated with the animation types used in this method, not controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:

0
source

Source: https://habr.com/ru/post/1215022/


All Articles