我正在尝试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
字母数据,如下图所示。
当我索引另一个字母时它不会改变。
有什么地方我错了吗?
请帮我。