0

我正在尝试UITableView在我的应用程序中编制索引,例如 iOS 音乐应用程序的歌曲。

所以我写了以下代码。

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

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

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.arrayOfSongs count];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] count];
}

但是,当我索引P字母时,它仍然显示A字母数据,如下图所示。

在此处输入图像描述

当我索引另一个字母时它不会改变。

有什么地方我错了吗?

请帮我。

4

1 回答 1

1

除了为部分索引标题使用数组外,您还应该将数据“分区”为部分。

可以在这里找到一个很好的教程:如何使用 UILocalizedIndexedCollat​​ion 将本地化索引添加到 UITableView(也就是将 AZ 索引添加到 UITableView)

于 2013-02-22T15:02:03.157 回答