UITableView分组页脚在重新加载后未更新

时间:2017-10-02 18:46:28

标签: ios objective-c uitableview

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

dispatch_async(dispatch_get_main_queue(), ^{

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

enter image description here

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

但是,正如您在GIF中看到的那样,首先loading按钮停留在那里。它甚至可以访问和工作。当我向上滚动时,它会消失,人们可以在底部看到它,这是正确的。但是在重新加载所有评论之后,它应该消失,但遗憾的是它仍然存在。

如果我使用reloadData,它可以正常工作。但我无法使用它,因为我还有其他部分,我不需要重新加载。

其次,即使我使用UITableViewRowAnimationNone,行项也会出现奇怪的动画/闪烁。在GIF中不可见

2 个答案:

答案 0 :(得分:0)

你应该实现" isTheLastSection"根据你的逻辑

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (isTheLastSection) {
         return 40;
    }
    return 0;
}

答案 1 :(得分:0)

为了向部分添加新行,您必须使用insertRowsAtIndexPaths而不是仅仅将新对象添加到数据源并重新加载部分。

以下是代码:

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