Is there a way to force a refresh of just a single header in UITableView?

后端 未结 4 947
半阙折子戏
半阙折子戏 2021-02-14 00:11

I have a UITableView where I want to force a refresh of just a specific section header row, not the data rows. For example, refresh the header for section 3. I know how to reloa

4条回答
  •  悲&欢浪女
    2021-02-14 00:26

    I beg to differ. I've run into this while deleting rows with custom section headers and (at least in iOS 6) you can simply call:

    [self tableView:self.tableView viewForHeaderInSection:[indexPath section]];
    

    And as long as you have proper code to return a view in that method, you can easily refresh the header for a specific section:

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
        if ([self tableView:tableView numberOfRowsInSection:section] == 0) {
    
            return nil; //hide the header if there are no rows...
    
        } else {
            // configure or refresh the header...
        }
    }
    

提交回复
热议问题