0

I have a tableview. I reload a section. My sectionheader has a line that requires to be drawn. The positioning of this line and how it’s drawn is based on contentview’s frame

  1. If if do tableview.reloadData() it get’s drawn correctly. Tableview header’s frame is non-zero
  2. If I do notesTable.reloadSections([1], with: .automatic) it doesn’t get drawn correctly. Tableview header’s frame is zero! ( I need to use reloadSections because I want to animate it. reloadData() doesn’t give any animation)

so a very watered down example of my viewForHeaderInSection is:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    // some code
     sectionView.setupUI()
    return sectionView
}

Header class:

class SectionHeaderclass: UITableViewHeaderFooterView{
    func setupUI(){
        let triangleViewArea = ViewWithTriangleLine(triangleCenter:Double(contentView.frame.width - 30))
    }
}

contentView.frame.width returns 0 if I animate the section reload. Why?! How can I fix this?

mfaani
  • 33,269
  • 19
  • 164
  • 293

1 Answers1

0

If you want to update header, and it has some drawing view, its better you call setNeedsDisplay() on headerView instead of reloading tableview. Note that reloadSections(...) updates cells in the sections not the header view.

  • dadash: I have to update the entire section.So reloading the header only isn't an option.The entire section needs to get reloaded + the line needs to get drawn correctly in the header. I've already seen [here](https://stackoverflow.com/questions/8658121/uitableview-reloadsections-reloaddata-header-view-becomes-blank/28056161?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa). I'm dequeueing/registering my header correctly. If I scroll down till the header goes off screen and then bring it back. The line is drown. It just seems that the frame isn't drawn during animation. – mfaani Apr 25 '18 at 16:21