Objective c sectionIndexTitlesForTableView的索引错误

Objective c sectionIndexTitlesForTableView的索引错误,objective-c,uitableview,Objective C,Uitableview,我使用的列表可以以各种方式排序,每次更改排序顺序时都会重新生成UITableView 我每次都以相同的方式设置sectionIndex,即: - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return [NSArray arrayWithObjects:@"•", @"•", @"•", @"•", @"•", @"•", @"•", @"•", @"•", @"•", nil]; } 问题

我使用的列表可以以各种方式排序,每次更改排序顺序时都会重新生成UITableView

我每次都以相同的方式设置sectionIndex,即:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return [NSArray arrayWithObjects:@"•", @"•", @"•", @"•", @"•", @"•", @"•", @"•", @"•", @"•", nil];
}
问题是,当我更改排序顺序(比如从国家改为城市名称)后,索引不再正常工作

似乎索引没有认识到tableview有不同数量的节

有没有办法找到合适的螺丝钉


干杯

在代码中尝试此逻辑

NSInteger section = [IndexPath section];

if (section ==0)
    // return sorted array for that section (1st section)

if (section ==1)
    // return sorted array for that section (2nd section)
见塞尔吉奥的评论:


  • 您是否正在实现
    tableView:sectionForSectionIndexTitle:atIndex

完成了…

您是否正在实现
tableView:sectionForSectionIndexTitle:atIndex
?你能提供代码吗?不,没有实现,但仔细阅读它可能会抓住线索我试试看……是的,就是这样。现在一切正常,谢谢:)