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:
- If I print the contentInset on returning it gives -44 (1 cell hidden, like in the pic). I'm unable to set the contentInset back to 0.0 (or anything else for that matter) as it doesn't seem to change anything.
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() 


UITableViewControlleror manually adding aUITableView?automaticallyAdjustsScrollViewInsets.UITableViewController. I add the search bar programmatically in theviewDidLoad. I have the same implementation in other views as well where it doesn't have the same error, maybe it's the detail view that's causing it.