2

I have been searching and trying to get my UITableView section header to allow multi line text but I cannot get it to work. This is what it's displaying as:

enter image description here

But the text is: What colour are the home shirts of Everton Football Club?

What I'm currently trying is:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        let label = UILabel()
        label.lineBreakMode = .byWordWrapping
        label.numberOfLines = 0
        label.text = question?.question
        return label
}

And place the following in the viewDidLoad event

tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension

But it hasn't made any difference. Can anyone help me out?

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
user1323
  • 91
  • 5
  • Possible duplicate of [Is it possible to obtain a dynamic table view section header height using Auto Layout?](https://stackoverflow.com/questions/29462331/is-it-possible-to-obtain-a-dynamic-table-view-section-header-height-using-auto-l) – Ozgur Vatansever Feb 20 '18 at 18:55

1 Answers1

3

instead of

tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension

use below

tableView.sectionHeaderHeight = UITableViewAutomaticDimension
tableView.estimatedSectionHeaderHeight = 44

for more information please read below answer https://stackoverflow.com/a/29763200/1320352

Bhushan Vaidya
  • 722
  • 1
  • 6
  • 17
  • Just cracked it before you posted this answer but this is the correct answer! Got the idea from https://stackoverflow.com/questions/33297371/estimatedheightforheaderinsection-acting-weird – user1323 Feb 20 '18 at 19:03