I have some weird behaviour on a TableView and hope someone could help me out.
I have a TableView with a searchbar in the navigation. The cells lead to a detail view. Whenever I search in the TableView and then hit a result cell to go to the detail view, on returning from the detail view to the TableView the first cell disappears underneath the opened search bar.
Searching:
On selecting the item (detail view) and then returning (using the nav bar) the first cell is hidden under the search bar:
Some things to note:
tableView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
print(tableView.contentOffset.y)
// -44.0
If the first cell is hidden and I hide the search bar by pushing the table down and then up again, the problem automatically disappears and the ContentInset restores to 0.0.
UPDATE: I found that the view restores itself as well after returning the app from the background:
I can't however reproduce that in code. I've tried:
view.setNeedsLayout()
view.layoutIfNeeded()
tableView.reloadData()
Solved, I set searchController.hidesNavigationBarDuringPresentation = false
, which caused the bug. See the answer on this post: Search Bar in a Navigation Item collapses and gets stuck under status bar upon navigation pop, on iOS 11.
Thanks for the help!