UITableViewRowAnimation 被忽略 [英] UITableViewRowAnimation is ignored

查看:24
本文介绍了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; 

现在这是我的问题:当插入新行时,它们总是在向下"滑动时进行动画处理.在无限向上滚动时,它看起来很糟糕.无论我是否通过 UITableViewRowAnimationNoneUITableViewRowAnimationTopUITableViewRowAnimationBottom 作为参数,都会发生这种情况 - 该选项似乎被完全忽略了.

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 是要走的路.我爱你,苹果.

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天全站免登陆