UITableViewRowAnimation被忽略 [英] UITableViewRowAnimation is ignored

查看:146
本文介绍了UITableViewRowAnimation被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NSFetchedResultsController 来填充我的表格。我的表中的数据按升序排列的时间戳排序(底部的最新消息)。更多数据通过无限滚动加载到顶部:例如当用户滚动到顶部时,会加载更多消息。我的 NSFetchedResultsControllerDelegate 按照惯例定义,如苹果文档中所推荐:通过

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 the bottom). More data is loaded via "infinite scroll" to the top: e.g. when user scrolls past the top, more messages are loaded. My NSFetchedResultsControllerDelegate is defined as usual, as recommended in the apple documentation: new rows are inserted via

- (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 作为参数 - 该选项似乎完全被忽略。

Now here is my problem: when new rows are inserted, they are always animated as sliding "down". On the infinite scroll upwards it looks bad. That happens regardless of whether I pass UITableViewRowAnimationNone, UITableViewRowAnimationTop or UITableViewRowAnimationBottom as the parameter - that option seems to be ignored entirely.

如何正确地为表格设置动画?

Any ideas how to animate the table properly?

推荐答案

所以我已经弄明白了。

WWDC 2011谈高级表视图技术明确表示UITableViewRowAnimationNone并不意味着没有动画(:

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

好像是有道理的。

动画参数只是定义如何将行插入空间(例如,从右/左/等滑动),转换到创建该空间是动画的,无论用户想要什么。

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.

所以是的,没有方式插入/删除/刷新单个单元格, reloadData 是要走的路。我爱你,Apple。

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

现在根据很多回答在stackoverflow上,也无法在不更改当前视图的情况下在表格顶部插入内容(例如,无用地插入东西而不改变用户看到的内容。最好的办法是在新数据到达后更改 contentOffset

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.

这篇关于UITableViewRowAnimation被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆