0

Happens only when compiled with Xcode9 and iOS 11 devices.

Section header does not automatically stick to the top leaving a space in the view through which content can be seen. (Screenshot included) Happens when tapped for full screen. But some times the header sticks to the top on the tap action
On scrolling up/down the header sticks to the top. (GIF included)

Screenshot

GIF

Correct me if I am wrong, the floating nature of section header is provided by UITableViewStyle set to plain.

tableView = UITableView()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44
tableView.cellLayoutMarginsFollowReadableWidth = false
tableView = UITableView(frame: self.view.frame, style: UITableViewStyle.plain)
tableView.sectionHeaderHeight = 44
//    tableView.estimatedSectionHeaderHeight = 0
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "content")
tableView.register(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: "hContent")
tableView.dataSource = self
tableView.delegate = self

Tried to set the estimatedSectionHeaderHeight to 0 (Disable it) as suggested here. But it did not work.

We tried reloading the tableView data in our hideNavBar func as suggested here for the similar problem. But that would scroll us to some other content.

Tried the following as suggested by other answer in our hideNavBar function and again facing the same issue where we are scrolled to some distant content.

tableView.reloadData()
tableView.layoutIfNeeded()
tableView.beginUpdates()
tableView.endUpdates() 
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
Dar
  • 57
  • 1
  • 11
  • Do you hide navBar on scroll down event too? There is this pod called `AMScrollingNavbar` which I use for similar functionality – Hunaid Hassan Feb 23 '18 at 07:30

1 Answers1

0

The change could be due to change in safe area constraints with iPhone X. So, instead of reloading the whole data, I suggest adding a reference for the frame. A workaround that worked perfectly for me even in iPhone X. Add the following lines in the respective functions.

func hideNavbar() and hideTabbar ()

tableView.frame = CGRect(x: 0, y: 0.01, width: view.bounds.width, height: view.bounds.height)

func showNavbar() and hideTabbar ()

tableView.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height)
Nish
  • 42
  • 7