Skip to content

Instantly share code, notes, and snippets.

@edwardinubuntu
Created April 16, 2012 10:44
Show Gist options
  • Save edwardinubuntu/2397642 to your computer and use it in GitHub Desktop.
Save edwardinubuntu/2397642 to your computer and use it in GitHub Desktop.
sectionIndexTitlesForTableView
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
NSMutableArray *toBeReturned = [[NSMutableArray alloc]init];
for(char c = 'A';c<='Z';c++)
[toBeReturned addObject:[NSString stringWithFormat:@"%c",c]];
return toBeReturned;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
NSInteger count = 0;
NSMutableArray *arrayOfCharacters = [[NSMutableArray alloc]init];
for(char c = 'A';c<='Z';c++)
[arrayOfCharacters addObject:[NSString stringWithFormat:@"%c",c]];
for(NSString *character in arrayOfCharacters) {
if(title.length > 0 && [character isEqualToString:[title substringToIndex:1]])
return count;
count ++;
}
return 0;// in case of some eror donot crash d application
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment