如果在ios8中使用搜索栏找不到结果,如何隐藏节标题

Asm*_*ita 5 iphone objective-c ios searchbar

如果名称存在,那么它将如下所示

如果名称不存在,那么它看起来像这样我想隐藏部分标题,如果名称不存在

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    if (_segment.selectedSegmentIndex==0)
    {
        return sortedKeys;
    }
    else
    {
       return sortedKeys1;
    }
}
Run Code Online (Sandbox Code Playgroud)

我使用这段代码,但如果名称不存在,我不想要章节标题,现在它给我所有章节标题

小智 1

如果没有行,则将该部分的标题设置为零。

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0)
 {
                return nil;
    } else {
        return "section title \(section)"
    }
   return @"";
}
Run Code Online (Sandbox Code Playgroud)

这会起作用。