【问题标题】:UITableView section headers are blank and flickeringUITableView 部分标题为空白且闪烁
【发布时间】:2010-06-12 03:44:42
【问题描述】:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];

if ([tempArray containsObject: [sectionInfo indexTitle]])
{
    [tempArray removeObjectAtIndex:[tempArray indexOfObject:[sectionInfo indexTitle]]];     
    return nil;
}else
{
    [tempArray addObject: [sectionInfo indexTitle]];
    return [sectionInfo indexTitle];

}
return [sectionInfo indexTitle];

}

上面的代码按字母顺序对单元格进行分组,但显示一个空白的灰色标题而不是适当的标题。这可能是因为我没有指定标题的数量吗?这自然是字母表中每个字母的单个标题。任何其他想法为什么单元格标题会在我滚动时闪烁白色到灰色,灰色到白色?

【问题讨论】:

  • 似乎如果我为 3.2 构建,它可以使用上面的逻辑。如果我使用 3.1.2 构建(我正在这样做),则会出现错误。

标签: iphone objective-c


【解决方案1】:

重复调用 tableView:titleForHeaderInSection: 似乎交替返回 [sectionInfo indexTitle] 和 nil。你为什么感到惊讶?

【讨论】:

  • 我见过数据按字母顺序分组的应用程序。所有以字母 A 开头的单元格在 A 下,B 在 B 下,依此类推。这将如何实现?我使用了错误的功能吗?
  • 您使用的是正确的功能,但我无法终生弄清楚 tempArray 应该做什么。尝试将整个函数体替换为return [sectionInfo indexTitle];