【问题标题】:wrong index when scroll in UITableView in iOS在 iOS 的 UITableView 中滚动时索引错误
【发布时间】: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


【解决方案1】:

除了对节索引标题使用数组外,您还应该将数据“分区”到节中。

一个很好的教程可以在这里找到:How to use UILocalizedIndexedCollation to add a localized index to a UITableView (aka adding an A-Z index to a UITableView)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多