テーブルビューにセクションが1つしかない場合でも、インデックス付きスクロールを設定することができます。私は50以上のソートされたテーブルエントリを持っていて、以下のようにA、B、C、Dなどを始めて行にジャンプしたいと思っています - これはかなり新しく、私が持っているものは近いですが、手伝ってくれますか ?次のように1セクションでのインデックス作成
私のコードは次のとおりです。 -
enter code here
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
[tempArray addObject:@"A"];
[tempArray addObject:@"B"];
[tempArray addObject:@"C"];
[tempArray addObject:@"D"];
[tempArray addObject:@"F"];
[tempArray addObject:@"G"];
[tempArray addObject:@"H"];
[tempArray addObject:@"J"];
[tempArray addObject:@"K"];
[tempArray addObject:@"L"];
[tempArray addObject:@"M"];
[tempArray addObject:@"P"];
[tempArray addObject:@"S"];
[tempArray addObject:@"T"];
[tempArray addObject:@"U"];
[tempArray addObject:@"V"];
return tempArray;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
if(index !=0){
[tableView scrollToRowAtIndexPath:[NSIndexPath
indexPathForRow:index inSection:0]
atScrollPosition:UITableViewScrollPositionTop animated:TRUE];
}
return index;
}
どのように正しく動作していませんか?また、[(NSArrary *)initWithObjects:...、nil]を見てください。 –
「正しく動作しない」とは、私たちが助けてくれるほど十分な情報だと誰かが思っているとき、私はいつも驚いています。 – sosborn