Alex Rivera | Logout

Changing UITableView section header without tableView:titleForHeaderInSection

Asked 2009-10-19T00:14:46.687
17

I'm trying to change the header title for a section in a UITableView when a cell from that section is selected. tableView:titleForHeaderInSection is triggered by the application, so that doesn't help. I can call reloadData, but the performance suffers because the app has to reload all the visible cells. I also tried to use a custom header, but that also results in some performance problems.

Is there any way to get a handle to the UILabel that the default header view uses and change its text manually?

Edit
Report

1 Answer

17

with:

[self.tableView headerViewForSection:i]

you could get the view for Section i and then "update" it manually

this even works if your view is just the auto-generated label, but you will have to resize it yourself. so if you try to:

[self.tableView headerViewForSection:i].textLabel.text = [self tableView:self.tableView titleForHeaderInSection:i];

you will set the text, but you would not set the label-size. You can get the needed size from NSString to set it yourself:

[label.text sizeWithFont:label.font];
answered 2013-03-06T10:05:39.123

Your Answer