UITableView grouped section footer not updating after reload

前端 未结 2 1082
旧巷少年郎
旧巷少年郎 2021-01-28 06:33

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()         


        
相关标签:
2条回答
  • 2021-01-28 07:06

    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.

    Here's the code:

    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];
    
    0 讨论(0)
  • 2021-01-28 07:07

    You should implement "isTheLastSection" according to your logic

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
        if (isTheLastSection) {
             return 40;
        }
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题