How to scroll to top in IOS7 UITableView?
ios, ios7, uitableview
Solution
By the help from some other answers here I managed to get it working. To avoid a crash I must first check that there are some sections. NsNotFound can be used as a row index if the first section has no rows. Hopefully this should be a generic function to be placed in a UITableViewController:
-(void) scrollToTop
{
if ([self numberOfSectionsInTableView:self.tableView] > 0)
{
NSIndexPath* top = [NSIndexPath indexPathForRow:NSNotFound inSection:0];
[self.tableView scrollToRowAtIndexPath:top atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}
Problem
In IOS6 I have the following code to scroll to the top of a UITableView ``` [tableView setContentOffset:CGPointZero animated:YES]; ``` In IOS7 this doesn't work anymore. The table view isn't scrolled completely to the top (but almost).