ios - 如果在 iOS 8 中使用搜索栏找不到结果,如何隐藏部分标题

标签 ios objective-c iphone searchbar

IF Name is present then it will look like this

IF Name is not present then it look like this i want to hide section title if name is not present

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

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

最佳答案

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

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

这会起作用。

关于ios - 如果在 iOS 8 中使用搜索栏找不到结果,如何隐藏部分标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33120078/

相关文章:

iphone - 为 iOS6.0 ARMv7 处理器构建 FFMPEG 库

ios - 如何使用 Alamofire 5.0.0-beta.3 (Swift 5) 上传图片(Multipart)

ios - 如何调整文本(字体)的大小以适应 UISegmentedControl 的 UISegment?

objective-c - NSOperationQueue 中不需要锁吗?

iphone - 如何删除UITableView中最后一个单元格的最后一个边框?

html - Bootstrap - 防止 Navbar 在 iPhone 上垂直堆叠

iphone - 使用 div 元素或按钮元素 [iPhone] [在 android 中] 哪个更好?

objective-c - 以编程方式创建的 UIBarButtonItem 未启动选择器操作

iphone - UICollectionViewContoller单元格格式和安排

objective-c - 撤消在主线程之外执行的核心数据插入