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 cel
Here's another way to do it:
UITableViewHeaderFooterView *headerView=[self.tableView headerViewForSection:1];
CATransition *animation = [CATransition animation];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionFade;
animation.duration = 0.35;
[headerView.textLabel.layer addAnimation:animation forKey:@"kCATransitionFade"];
headerView.textLabel.text=[self tableView:self.tableView titleForHeaderInSection:1];
[headerView.textLabel sizeToFit];
It worked for me to just reload the section with reloadSections
on my table view
Here's a UITableView extension that's a handy shortcut for refreshing the tableView header/footer titles, based on some of the answers above (note the artificial uppercasing of the header title).
extension UITableView {
func refreshHeaderTitle(inSection section: Int) {
UIView.setAnimationsEnabled(false)
beginUpdates()
let headerView = self.headerView(forSection: section)
headerView?.textLabel?.text = self.dataSource?.tableView?(self, titleForHeaderInSection: section)?.uppercased()
headerView?.sizeToFit()
endUpdates()
UIView.setAnimationsEnabled(true)
}
func refreshFooterTitle(inSection section: Int) {
UIView.setAnimationsEnabled(false)
beginUpdates()
let footerView = self.footerView(forSection: section)
footerView?.textLabel?.text = self.dataSource?.tableView?(self, titleForFooterInSection: section)
footerView?.sizeToFit()
endUpdates()
UIView.setAnimationsEnabled(true)
}
func refreshAllHeaderAndFooterTitles() {
for section in 0..<self.numberOfSections {
refreshHeaderTitle(inSection: section)
refreshFooterTitle(inSection: section)
}
}
}
This is how you do it in Swift 3.0
tableView.beginUpdates()
tableView.headerView(forSection: indexPath.section)?.textLabel?.text = "Some text"
tableView.endUpdates()