Iphone UITableView节标题为空且闪烁 -(NSString*)表视图:(UITableView*)表视图标题标题标题部分:(NSInteger)部分{ id sectionInfo=[[self.fetchedResultsController节]objectAtIndex:section]; 如果([tempArray containsObject:[sectionInfo indexTitle]]) { [tempArray removeObjectAtIndex:[tempArray indexOfObject:[sectionInfo indexTitle]]; 返回零; }否则 { [tempArray addObject:[sectionInfo indexTitle]]; 返回[sectionInfo indexTitle]; } 返回[sectionInfo indexTitle];

Iphone UITableView节标题为空且闪烁 -(NSString*)表视图:(UITableView*)表视图标题标题标题部分:(NSInteger)部分{ id sectionInfo=[[self.fetchedResultsController节]objectAtIndex:section]; 如果([tempArray containsObject:[sectionInfo indexTitle]]) { [tempArray removeObjectAtIndex:[tempArray indexOfObject:[sectionInfo indexTitle]]; 返回零; }否则 { [tempArray addObject:[sectionInfo indexTitle]]; 返回[sectionInfo indexTitle]; } 返回[sectionInfo indexTitle];,iphone,objective-c,Iphone,Objective C,} 上面的代码按字母顺序对单元格进行分组,但显示一个空白的灰色标题,而不是相应的标题。这可能是因为我没有指定标题的数量吗?这自然是字母表中每个字母的一个标题。还有什么其他想法可以解释为什么单元格标题在我滚动时会从白色变为灰色,从灰色变为白色?反复调用tableView:TitleForHeaderSection:会交替返回[sectionInfo indexTitle]和nil。你为什么感到惊讶?我看到过数据按字母顺序分组的应用程序。所有单元格均以字母A开头,A下以字母A开头,B下以字母B开头,

}


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

反复调用tableView:TitleForHeaderSection:会交替返回[sectionInfo indexTitle]和nil。你为什么感到惊讶?

我看到过数据按字母顺序分组的应用程序。所有单元格均以字母A开头,A下以字母A开头,B下以字母B开头,依此类推。这将如何实现?我用错函数了吗?你用的是正确的函数,但我一辈子都搞不清楚tempArray应该做什么。尝试用
return[sectionInfo indexTitle]替换整个函数体似乎如果我为3.2构建,它可以与上面的逻辑一起工作。如果我使用3.1.2(我正在这么做)构建,就会出现错误。
- (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];