In viewWillAppear, I have added UISearchBar as my headerview of UITableView. When view loads, I hides UISearchbar under <
In earlier versions of the iOS SDK, methods such as viewWillAppear ran on the main thread, they now run on a background thread which is why the issue now occurs.
Most callbacks tend to fire on a background thread so always check for thread safety when doing UI calls.
Dispatch the change to the content offset on the main thread:
Objective C
dispatch_async(dispatch_get_main_queue(), ^{
CGPoint offset = CGPointMake(0, self.searchBar.bounds.height)
[self.tableView setContentOffset:offset animated:NO];
});
Swift 3
DispatchQueue.main.async {
let offset = CGPoint.init(x: 0, y: self.searchBar.bounds.height)
self.tableView.setContentOffset(offset, animated: false)
}