1

The premise is simple. I have a UITablewView. I have a storyboard where I configured two prototype cells, one has a Reuse Identifier of headerCell, the other's Reuse Identifier is cell. I am instantiating a custom header cell like this in my UITableViewController:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    MyHeaderCell* headerCell = [tableView dequeueReusableCellWithIdentifier:@"headerCell"];
    headerCell.delegate = self;

    return headerCell;
}

My headerCell has a button on it, and when that button is tapped, it calls [_delegate toggleHeaderSize]. You can see above that the delegate property is simply the UITableViewController. Here is the toggleHeaderSize method:

-(void)toggleHeaderSize {
    [self.tableView beginUpdates];

    if (headerHeight == 100) {
        headerHeight = 120;
    } else {
        headerHeight = 100;
    }
    [self.tableView endUpdates];

//    [self.tableView reloadData];

}

That headerHeight variable is used in the heightForHeaderInSection method, like this:

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return headerHeight;
}

The header changes size, but it's weird. The table slides down, but the header doesn't actually grow. If I scroll the table just one pixel, the header seems to realize it needs to redraw, and it snaps to size.

I think I've read about every SO post about resizing header cells. They all seem to think the magic is with the beginUpdates/endUpdates dance. These do seem to be necessary, but it doesn't solve the problem of redrawing.

Here's an animated GIF of my problem. EDIT: I can't post the animated GIF since I don't have 10 reputation points, but if you go to http://nspaul.imgur.com/all/ you can find it :-)

I'd love any guidance. I can post more code if someone would like. I'll even post the whole project to Github if that helps.

iBhavin
  • 1,261
  • 15
  • 30
Paul Brown
  • 23
  • 5
  • what do you want increase your headerCell height or your tableview header height? – Ravi Aug 08 '14 at 05:40
  • Since I a using the headerCell in `viewForHeaderInSection`, wouldn't that make headerView the tableviewHeader? Or, is there a significant difference between the headerCell and the tableview header? If there's a better way to do this, please let me know. The goal here is to make that cell, which I am using as the header, bigger, and have it animate. – Paul Brown Aug 08 '14 at 12:37

1 Answers1

0
-(void)toggleHeaderSize {
    if (headerHeight == 100) {
        headerHeight = 120;
    } else {
        headerHeight = 100;
    }    
    [self.tableView reloadSections:mySections withRowAnimation:UITableViewRowAnimation];
}

Methods beginUpdates and endUpdates only create transaction for animations. You need method which will reload affected sections.

ksysu
  • 311
  • 4
  • 6
  • I tried adding a call to that method, which in my case looks like this: `[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];` The headerCell just disappears, and I get `no index path for table cell being reused` twice in my console. – Paul Brown Aug 08 '14 at 12:40
  • Try to look here: http://stackoverflow.com/questions/18490621/no-index-path-for-table-cell-being-reused – ksysu Aug 08 '14 at 14:47