Skip to content

Instantly share code, notes, and snippets.

@Tricertops
Created September 28, 2013 16:57
Show Gist options
  • Select an option

  • Save Tricertops/6744074 to your computer and use it in GitHub Desktop.

Select an option

Save Tricertops/6744074 to your computer and use it in GitHub Desktop.
Animated scrolling for table view section index.
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
NSUInteger section = ...
CGRect rect = [self.tableView rectForSection:section];
// Include content inset
rect.origin.y -= self.tableView.contentInset.top;
// Restore previous offset and animate to destination
CGPoint offset = self.tableView.contentOffset;
[[NSOperationQueue mainQueue] asynchronous:^{
self.tableView.contentOffset = offset;
[self.tableView setContentOffset:rect.origin animated:YES];
}];
return section;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment