Search code examples
iosxcodetableviewtableheadernstableheaderview

tableHeaderView preserves state when popping viewController except ContainerViewController


I have a tableViewController with a tableHeaderView. When I'm at the top of the tableView and I scroll the tableView up slightly the tableHeaderView is hidden and can reappear again by scrolling down slightly. This is the default behaviour.

When I push to a viewController then pop back to the tableViewController, the state of the tableHeaderView is preserved. i.e., if it was hidden it remains hidden and if it was visible it remains visible.

However, for some reason when I push to another viewController that has a containerView and then pop back, the tableHeaderView always displays. Even if it was hidden before pushing.


Solution

  • The Issue was that I had checked Hide Bottom Bar On Push in storyboard on the viewController that I was pushing to. For some reason this caused the tableHeaderView to always display when popping back. Unchecking this fixed the problem. Instead the tabBar can be hidden in viewDidLoad of the pushed viewController with the following:

    self.tabBarController?.tabBar.isHidden = true
    

    Hope this will help somebody.