UITableViewRowAnimation is ignored

纵饮孤独 提交于 2019-11-29 02:35:38

Please try as below.

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

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.

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.

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];
                }];

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:.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!