Skip to content

Instantly share code, notes, and snippets.

@arisro
Created April 19, 2013 14:10
Show Gist options
  • Save arisro/5420595 to your computer and use it in GitHub Desktop.
Save arisro/5420595 to your computer and use it in GitHub Desktop.
// dataArray is the nsdictionary/array containing you list of names; we take the 1st letter of each, and compare it with the title of the Index the user "clicked" on
// we cycle through all your names until we find a name starting with the letter that he touched in the index. When we found the name, we scroll the table tot that row.
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
for (int i = 0; i< [dataArray count]; i++) {
NSString *letterString = [[dataArray objectAtIndex:i] substringToIndex:1];
if ([letterString isEqualToString:title]) {
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment