Reloading tableView header in ios7

后端 未结 2 1173
野趣味
野趣味 2021-01-04 14:10

How can I do it without reloading all table?

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UIView *header;

         


        
相关标签:
2条回答
  • 2021-01-04 14:49

    You have to reload the whole section to reload the header.

    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation: UITableViewRowAnimationAutomatic];
    

    OR

    You could grab a handle to the view and update it manually:

    UIView *headerView = [self.tableView headerViewForSection:section];
    //... update your view properties here
    [headerView setNeedsDisplay];
    [headerView setNeedsLayout];
    
    0 讨论(0)
  • 2021-01-04 14:55

    You need to use -reloadSections:withRowAnimation:

    So when you need to update your headers:

    NSIndexSet *headers = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [self.tableView numberOfSections])];
    [self.tableView reloadSections:headers withRowAnimation:UITableViewRowAnimationAutomatic];
    

    If you've only got one section (as you just mentioned in your updated question) you can just call

    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
    
    0 讨论(0)
提交回复
热议问题