0

アルファベット順のスクロールを使用している UITableView がありますが、特定の文字にタブを付けると、それは実行されません。サンプルとして、「G」にタブを付けると「G」にジャンプせず、26文字下にスクロールするだけです.

マイコード

 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;
}

そこにブレークポイントを追加すると、indexForFirstChar の何かが間違っていると思います。すべての文字をスローするだけで、特定の 1 つにジャンプしません。

このテーブル ビューにはセクションがありません

助けてくれてありがとう!

4

2 に答える 2