I have a UITableView that is using alphabetical scroll but when I tab on a specific letter it is not doing . As sample if i tab on "G" its not jumping to "G" it is just scrolling 26 letters down why so ever .
My Code
alphabetical =[NSArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", nil];
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return alphabetical;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
NSInteger newRow = [self indexForFirstChar:title inArray:alphabetical];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:newRow inSection:0];
[tableView scrollToRowAtIndexPath:newIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
return index;
}
- (NSInteger)indexForFirstChar:(NSString *)character inArray:(NSArray *)array
{
NSUInteger count = 0;
for (NSString *str in array) {
if ([str hasPrefix:character]) {
return count;
}
count++;
}
return 0;
}
I think something with my indexForFirstChar is wrong when I add there a breakpoint it is just going throw all letters and its not jumping to one specific ..
I have no sections in this table view
Thanks for help and fast answer !!