显示uitableview的局部字母索引



是否有视图显示uitableview的局部字母索引?这意味着,如果我更改系统语言,索引标题也应该基于选择的语言并敲击它们,请带我到tableview上的各个部分。

我是一个相对较新的,我围绕着s.o徘徊,但只能看到如何向他们展示特定语言的英语,但是如果我更改我的系统语言,我也希望我的索引标题也更改。

这就是我所做的 -
我有一个字母

@[@"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",@"#"]

我从

返回
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return alphabetArray;
} 
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
  // i go to respective index when i tap on some title
} 

现在有人可以告诉我如何本地化。例如韩国人有这个系列

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, ㄱ, ㄴ, ㄷ, ㄹ, ㅁ, ㅂ, ㅅ, ㅇ, ㅈ, ㅊ, ㅋ, ㅌ, ㅍ, ㅎ, #

我知道有类似

的东西
[UILocalizedIndexedCollation currentCollation].sectionTitles.count . 

这将为我提供基于当前语言环境的标题计数,但我可以以某种方式使用它。有人可以阐明这里可以做什么吗?

预先感谢!

使用 UILocalizedIndexedCollation是您想要的。

对于您执行的部分索引标题:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return [UILocalizedIndexedCollation currentCollation].sectionIndexTitles;
}

,然后:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index];
}

假设您需要匹配截面索引标题的部分标题,并且您的数据分为适当的部分以匹配,则可以:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [UILocalizedIndexedCollation currentCollation].sectionTitles[section];
}

最新更新