Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing UITableView's section header/footer title without reloading the whole table view

Is there any way to reload the section header/footer of a table view without calling [tableView reloadData];?

In fact, I want to show the number of cells in a table view's section in its section footer. The table view is editable and I delete or insert rows using

– insertRowsAtIndexPaths:withRowAnimation: – deleteRowsAtIndexPaths:withRowAnimation: 

It seems that these methods do not update the section footer. Strangely, when I call these methods the table view data-source method

- (NSString *)tableView:(UITableView *)table titleForFooterInSection:(NSInteger)section  

is called (twice!) but it does not update the table view with the new values!!

Anyone has any idea how to fix this problem?

like image 342
Ali Avatar asked Dec 03 '10 15:12

Ali


1 Answers

If you just have a basic text header or footer, you can access them directly:

[tableView footerViewForSection:indexPath.section].textLabel.text = [self tableView:tableView titleForFooterInSection:indexPath.section]; 

similarly for the header:

[tableView headerViewForSection:indexPath.section].textLabel.text = [self tableView:tableView titleForHeaderInSection:indexPath.section]; 
like image 84
Nico teWinkel Avatar answered Sep 21 '22 03:09

Nico teWinkel