Reputation: 21
I am currently encountering a rather large problem in iOS 8 in regards to UITableViews. What this part of my app does is allow the user to search through a list of strings, and each time the search results are reloaded, the result table is programmatically scrolled to the top (If I don't do this, then there's a case where I get 50+ results, scroll down to the bottom, then search again but only get 5-10 results. When this happens, the table wouldn't automatically scroll back up to the top, so it would give the illusion that there are no results.)
After searching and reloading the search results table, I use the following code to scroll the search results table back up to the top:
[self.searchDisplayController.searchResultsTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
This code functions properly in iOS 7, but when I use it in iOS 8, it works properly maybe once or twice, but after that, it will scroll the table down very very far. (If I search enough times, it can take a good 8-10 seconds of scrolling to get back up to the 2-3 search results).
I've tried everything I can think of and it still won't function in iOS 8 like it did in iOS 7. Does anybody know why this is happening and/or how to solve it?
Upvotes: 0
Views: 3321
Reputation: 5064
Only working solution in iOS is by doing setContentOffset, here I wrote function to scrollToEnd of tableView:
- (void)scrollToEnd
{
CGPoint contentOffset = CGPointZero;
contentOffset.y = self.tableView.contentSize.height - self.tableView.frame.size.height;
[self.tableView setContentOffset:contentOffset animated:YES];
}
Upvotes: 0
Reputation: 21
I ended up discovering the inherited method setContentOffset and that worked like a charm. This was the code I implemented for iOS 8 that now appears to be working correctly:
[self.searchDisplayController.searchResultsTableView setContentOffset:CGPointZero];
Upvotes: 2