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

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


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];


This should work:

    UIView.setAnimationsEnabled(false)    tableView.beginUpdates()    if let containerView = tableView.footerViewForSection(0) {        containerView.textLabel!.text = "New footer text!"        containerView.sizeToFit()    }    tableView.endUpdates()    UIView.setAnimationsEnabled(true)


I managed to do it in an indirect way: I created a UILabel and set it as section header/footer.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {    // update sectionFooterView.text        return sectionFooterView;}- (void)viewDidLoad {    // create sectionFooterView in Interface Builder, change the frame here    // use Font-size:15 , BG-Color: clearColor , text-Color: RGB=(97,105,118)     // and Text-alignment:Center to look like table view's original footer    sectionFooterView.frame = CGRectMake(0, 10, 320, 12);}

Does anyone know a way to do this without setting a custom footer view?


matomo