Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force a refresh of just a single header in UITableView?

I have a UITableView where I want to force a refresh of just a specific section header row, not the data rows. For example, refresh the header for section 3. I know how to reload an entire section (header plus data), but can just the section header be refreshed?

EDIT: When data changes in one section of the table I want to update information in the header of a DIFFERENT section. Therefore, I need to get a reference to the section header and then refresh it.

like image 425
ChrisP Avatar asked Jan 04 '12 18:01

ChrisP


2 Answers

If the header is a custom UIView, then you can just call setNeedsDisplay on the UIView rather than on the UITableView.

like image 147
PengOne Avatar answered Oct 17 '22 05:10

PengOne


Well, in my case, after some asynchronous task i need to update my custom section header view.

and I get it to update it's height using : This Swift 3+ Code

//to reload your cell data
self.tableView.reloadData()
DispatchQueue.main.async {
// this is needed to update a specific tableview's headerview layout on main queue otherwise it's won't update perfectly cause reloaddata() is called
  self.tableView.beginUpdates()
  self.tableView.endUpdates()
}        
like image 35
Rafat touqir Rafsun Avatar answered Oct 17 '22 06:10

Rafat touqir Rafsun