【发布时间】:2013-02-22 14:38:20
【问题描述】:
我正在尝试在我的应用程序中索引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 字母数据,如下图所示。
当我索引另一个字母时它不会改变。
我有什么不对的地方吗?
请帮帮我。
【问题讨论】:
-
numberOfRowsInSection似乎关闭了,那不应该返回数组中特定部分的数字项吗? -
那么我应该返回哪个值?当我删除该属性时,会发生错误。
标签: ios cocoa-touch uitableview indexing