我想知道是否可以提供帮助,即使您在表格视图中只有1个部分,也已经可以设置索引滚动。我有很多排序的表条目(超过50个),希望跳转到以下以A,B,C,D等开头的行-我对此很陌生,但是我已经关闭了,但是不能正常工作-你能帮我吗 ?
我的代码如下:
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;
}
Run Code Online (Sandbox Code Playgroud)