How do I cover the “no results” text in UISearchDisplayController's searchResultTableView?

I don't want to show the "no results" text while my server is processing a search query.

I figured out the exact coordinates of the table cell that contains the label and attempted to cover it.

self.noResultsCoverView = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 44.0, 320.0, 43.0
)] autorelease];
self.noResultsCoverView.backgroundColor = [UIColor whiteColor];
[self.searchDisplayController.searchResultsTableView addSubview:self.noResultsCoverView];

To my chagrin, my cover was above the table view, but below the label. I need the cover to be above the label. searchResultsTableView::bringSubviewToFront didn't work, which makes me believe that the label isn't a child of the searchResultsTableView at all.

BTW, this Stack Overflow answer doesn't quite work for me. It works on the very first search, but flashes a weird black cover on subsequent searches.

this should do the work properly. The code to return at least one cell:

BOOL ivarNoResults; // put this somewhere in @interface or at top of @implementation
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{if (tableView == self.searchDisplayController.searchResultsTableView) {if (filteredList.count == 0) {ivarNoResults = YES;return 1;} else {ivarNoResults = NO;return [filteredList count];}}// {…}// return the unfiltered array count
}

and for "showing" the clean cell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{if (tableView == self.searchDisplayController.searchResultsTableView && ivarNoResults) {static NSString *cleanCellIdent = @"cleanCell";UITableViewCell *ccell = [tableView dequeueReusableCellWithIdentifier:cleanCellIdent];if (ccell == nil) {ccell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cleanCellIdent] autorelease];ccell.userInteractionEnabled = NO;}return ccell;}// {…}
}

share|improve this answer
answered Aug 2 '12 at 8:39
relikd
7,48541956

   
up vote0down vote

You need to realize that when you have a UISearchDisplayController, and the search bar is active, the UITableView argument passed into your UITableView data source and delegate methods is in fact NOT your tableView object, but a tableView managed by theUISearchDisplayController, intended to display "live" search results (perhaps results filtered from your main data source, for example).

You can easily detect this in code, and then return the appropriate result from the delegate/data source method, depending on which tableView object is asking.

For example:

- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section
{if (tv == self.searchDisplayController.searchResultsTableView) {// return the number of rows in section for the visible search results.// return a non-zero value to suppress "No results"} else {// return the number of rows in section for your main data source}
}

The point is that your data source and delegate methods are serving two tables, and you can (and should) check for which table is asking for data or delegation.

By the way, the "No results" is (I believe) provided by a background image which theUISearchDisplayController displays when the delegate says there are no rows... You are not seeing a 2-row table, the first blank and the second with text "No results". At least, that's what I think is happening there.

share|improve this answer
answered Jul 27 '12 at 19:53
MarkGranoff
10.2k2338

   
up vote0down vote

I haven't tried it myself, you can give it a try-- Link

Regards, 
Amar

share|improve this answer
answered Jul 30 '12 at 3:44
Amar
961214

   
因为产生的UILabel@“No Resulte”有延迟,如果不延迟检测是检测不出来的
up vote-2down vote

Try this it worked for me

In the UISearchDisplayController delegate do this:=

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.001);dispatch_after(popTime, dispatch_get_main_queue(), ^(void){for (UIView* v in self.searchDisplayController.searchResultsTableView.subviews) {if ([v isKindOfClass: [UILabel class]] && [[(UILabel*)v text] isEqualToString:@"No Results"]) {[(UILabel*)v setText:@""];break;}}});return YES;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/zsw-1993/p/4879967.html

How do I cover the “no results” text in UISearchDisplayController's searchResultTableView?相关推荐

  1. 免费视频转文字-音频转文字软件:网易见外工作台, Speechnotes, autosub, Speech to Text, 百度语音识别

    文章目录 网易见外工作台(推荐) Chrome插件 Speechnotes autosub 百度语音识别API IBM的Speech to Text(不推荐) 此文首发于我的Jekyll博客:zhan ...

  2. Text Classification Algorithms: A Survey——1. Introduction引言

    "Most text classification and document categorization systems can be deconstructed into the fol ...

  3. 内存数据库mongodb_内存和磁盘性能如何影响您的MongoDB数据库

    内存数据库mongodb This article was originally published on MongoDB. Thank you for supporting the partners ...

  4. 斯坦福大学计算机类课程视频

    斯坦福大学计算机类课程都是以CS开头编号,可以在网址https://exploredegrees.stanford.edu/coursedescriptions/cs/查询,在网上可以登录查看课程的课 ...

  5. Windows下使用Tesseract进行OCR文字识别

    Windows下使用Tesseract进行OCR文字识别 Tesseract最初由惠普实验室支持,用于电子版文字识别,1996年被移植到Windows上,1998年进行了C++化,在2005年Tess ...

  6. 使用深度学习opencv 进行人脸年龄的实时检测

    2020-05-09 21:36:08 往期的文章我们分享了人脸的识别以及如何进行人脸年龄的检测,本期文章我们结合人脸识别的 模型进行人脸年龄的实时检测 人脸年龄的检测步骤 0.打开摄像头,获取图片数 ...

  7. jQuery常用方法一览

    Attribute: $("p").addClass(css中定义的样式类型); 给某个元素添加样式 $("img").attr({src:"test ...

  8. python爬虫新手项目-Python爬虫实战之取电影天堂,,新手练手项目

    前言: 本文非常浅显易懂,可以说是零基础也可快速掌握.如有疑问,欢迎留言,笔者会第一时间回复.本文代码存于github 一.爬虫的重要性: 如果把互联网比喻成一个蜘蛛网,那么Spider就是在网上爬来 ...

  9. jQuery 事件方法大全

    Dom : Attribute:$("p").addClass(css中定义的样式类型); 给某个元素添加样式$("img").attr({src:" ...

最新文章

  1. html脚本详解,HTML脚本教程详解
  2. oracle创建索引---如何创建所以
  3. [图解]在输入框和文本框中获取和设置光标位置,以及选中文本和获取选中文本值的方法 --- 详解,兼容所有浏览器。...
  4. Oracle数据库相关
  5. Rational rose的安装
  6. [html] 开发静态页面时,不依赖node相关的工具,如何提取出公共部分并引入?
  7. React中的CSS——styled-components
  8. Linux 实操———CentOS 6 安装配置 Oracle JDK 1.8
  9. 炮兵阵地(POJ-1185)
  10. fread 单独测试没有问题 在正式项目里面丢数据 可能是系统资源不足 预读出了问题
  11. gini指数与cart 决策树
  12. 基于抛物线过渡(梯形加减速)的空间直线插补算法与空间圆弧插补算法(Matlab)
  13. html 调用es2015模块,给大家分别介绍一下CommonJS和ES2015的import
  14. 卸载windows电脑软件,这样卸载才干净
  15. python运维自动化脚本案例-python自动化运维脚本范例
  16. 《士兵突击》之成才:请关爱我们自己的另一半
  17. 影响关键词排名的因素有哪些?
  18. 2021爱智先行者—软件入门及远程控制开关灯
  19. Unity个人版切换到加强版
  20. java 在线聊天室_一万人一起在线聊天的聊天室,怎样用Java实现?

热门文章

  1. [WP]关于WP7的后台的一些小事情
  2. c++心得之struct和class(结构体和类)
  3. PermGen space
  4. Kubernetes Pod的生命周期(Lifecycle)
  5. 花呗分期计算器_花呗分期最多能分多久?
  6. Python高级网络编程系列之第一篇
  7. matlab_exercise(4)----第一题
  8. Unencrypted connection refused. Goodbye. Connection closed by foreign host.
  9. 【LeetCode】004 Median of Two Sorted Arrays 两个排序数组合并后的中位数
  10. 项目经理的几个重要转变