UITableViewRowAnimation is ignored

后端 未结 5 1385
感动是毒
感动是毒 2020-12-16 07:27

I\'m using NSFetchedResultsController to populate my table. The data in my table is sorted according to the timestamp in the ascending order (latest message at

相关标签:
5条回答
  • 2020-12-16 07:50

    Are you breaking the data into sections? If you are, check your implementation of controller:didChangeSection:atIndex:forChangeType: as new section inserts will be animated with the animation types used in that method, not controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:.

    0 讨论(0)
  • 2020-12-16 07:55

    Please try as below.

    [CATransaction setDisableActions:YES];
    [self.table insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
    [CATransaction setDisableActions:NO]; // reset to original value
    
    0 讨论(0)
  • 2020-12-16 08:03

    I found a way to disable insert/delete cells animation.

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

    It's perfectly doing work.

    0 讨论(0)
  • 2020-12-16 08:04

    So I've figured it out.

    WWDC 2011 talk "Advanced Table View Techniques" explicitly says that UITableViewRowAnimationNone does not mean no animation (:

    As if it made sense.

    The animation parameter merely defines how the row is inserted into the space (e.g. slide from the right/left/etc), the transitions to create that space are animated regardless of what user wants.

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

    Now according to many answers on stackoverflow there is also no way to insert content at the top of the table without changing the current view (e.g. seemlessly insert stuff with no changes to what user sees at all). The best one can do is to change the contentOffset after the new data have arrived.

    0 讨论(0)
  • 2020-12-16 08:05

    As of iOS 7.0, you can wrap the code in a performWithoutAnimation: block, like so:

    [UIView performWithoutAnimation:^{
                        [self.tableView beginUpdates];
                        [self.tableView deleteRowsAtIndexPaths:rowsToRemove withRowAnimation:UITableViewRowAnimationNone];
                        [self.tableView endUpdates];
                    }];
    
    0 讨论(0)
提交回复
热议问题