我正在使用NSFetchedResultsController
填充我的表。我的表中的数据是根据时间戳以升序排序的(底部是最新消息)。通过“无限滚动”将更多数据加载到顶部:当用户滚动到顶部时,将加载更多消息。我的NSFetchedResultsControllerDelegate
照常定义,如苹果文档中所建议:通过插入新行
- (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;
现在这是我的问题:插入新行时,它们总是以滑动“向下”的方式进行动画处理。在无限向上滚动时,它看起来很糟糕。
无论我传递
UITableViewRowAnimationNone
,UITableViewRowAnimationTop
还是UITableViewRowAnimationBottom
作为参数,都会发生这种情况-该选项似乎被完全忽略了。有任何想法如何正确设置表格动画吗?
最佳答案
请尝试以下方法。
[CATransaction setDisableActions:YES];
[self.table insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
[CATransaction setDisableActions:NO]; // reset to original value