重新加载后,UITableView分组的节页脚未更新 [英] UITableView grouped section footer not updating after reload

查看:63
本文介绍了重新加载后,UITableView分组的节页脚未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在分组的UITableView中,我有3个或2个部分(取决于数据源).我正在尝试通过以下方式重新加载最后一部分:

I have 3 or 2 sections (depending on datasource), in my grouped UITableView. I am trying to reload the last section via:

dispatch_async(dispatch_get_main_queue(), ^{

            [UIView performWithoutAnimation:^{
                [feedDetailTB reloadSections:[NSIndexSet indexSetWithIndex:feedDetailTB.numberOfSections-1] withRowAnimation:UITableViewRowAnimationNone];
            }];
        });

首先,页脚永远不会消失.数据源基本上会跟踪是否有更多注释(简单加载更多功能).在viewForFooterInSection中,当所有注释均已加载时,我只是return nil.

First of all, the footer never disappears. The data source basically keeps track of whether there are more comments or not (a simple load more functionality). In the viewForFooterInSection I simply return nil, when all the comments have been loaded.

但是,正如您在GIF中看到的那样,起初loading按钮停留在该位置.它甚至可以访问并且有效.当我向上滚动时,它消失了,并且可以在底部看到它,这是正确的.但是,在重新加载所有评论之后,它应该消失了,但遗憾的是,它仍然存在.

But, as you see in the GIF, at first the loading button stays there. It is even accessible and works. When I scroll up, it vanishes and one can see it in the bottom, which is correct. But after all the comments have been reloaded, it should vanish, but sadly it stays there.

如果我使用reloadData,则效果很好.但是我无法使用它,因为我还有其他部分,不需要重新加载.

If I use reloadData it works fine. But I can't used it, since I have other sections, which I don't need to reload.

第二,即使使用UITableViewRowAnimationNone,行项目也会出现奇怪的动画/闪烁.在GIF中不可见

Second, there is a weird animation/flickering of the row items, even when I have used UITableViewRowAnimationNone. Not visible in the GIF

推荐答案

要向节中添加新行,您必须使用insertRowsAtIndexPaths而不是仅向数据源中添加新对象并重新加载节.

In order to add new rows to a section, you must use the insertRowsAtIndexPaths rather than just adding new objects to data source and reloading a section.

代码如下:

NSMutableArray *newCommentsIndexPath = [[NSMutableArray alloc] init];

                for (NSInteger i = currentCount; i < (_postDetailDatasource.commentsFeedInfo.allCommentsArray.count + serverComments.count); i ++)
                {
                    NSIndexPath *idxPath = [NSIndexPath indexPathForRow:i inSection:sectionNumber];

                    [newCommentsIndexPath addObject:idxPath];
                }

                [_postDetailDatasource.commentsFeedInfo.allCommentsArray addObjectsFromArray:serverComments];

                [feedDetailTB beginUpdates];

                [feedDetailTB insertRowsAtIndexPaths:newCommentsIndexPath withRowAnimation:UITableViewRowAnimationFade];

                [feedDetailTB endUpdates];

这篇关于重新加载后,UITableView分组的节页脚未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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