In viewWillAppear
, I have added UISearchBar
as my headerview of UITableView
. When view loads, I hides UISearchbar
under <
You need to hide the search bar by yourself when you scroll the table. So don't put it as a UITableView
header. You could hide it by setting its height to zero. That way if your table view is set to auto resize, it will expand.
self.tableView.contentInset = UIEdgeInsetsMake(self.navigationController.navigationBar.frame.size.height -80, 0, 0, 0);
In my case the problem was that I called
[_myGreatTableView reloadData];
before getting the _tableView.contentOffset.y
. This always returned '0'.
So I switched the order of these methods and now it works.
This is quite a strange behavior in my opinion, because offset returned 0 but the UI still kept the scroll position of the table.
I fixed it with layoutIfNeeded()
self.articlesCollectionView.reloadData()
self.articlesCollectionView.layoutIfNeeded()
self.articlesCollectionView.setContentOffset(CGPoint(x: 0, y: 40), animated: false)
In iOS 7/8/9 simple self.automaticallyAdjustsScrollViewInsets = NO; solved the problem in my case
The problem is auto masking. Select your table and make sure you have selected all the lines, as in the image below.