IOS:自定义UISearchDisplayController的cancel和no results
来源:互联网 发布:传奇推广员 知乎 编辑:程序博客网 时间:2024/06/04 19:18
网上好多方法都是在UISearchDisplayDelegate的方法中添加修改子视图的代码,如下所示:
还是放到一样的代理方法中。经测试无问题。目前对于dispatch之类的东东还不是很熟悉,大概意思能看出来是推迟了方法的执行,保证执行的时候这个UILabel已经被添加到父视图上。(真的能万无一失的确保吗?)
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{ [self filterContentForSearchText:searchString]; if ([filteredListPinYin count] == 0) { UITableView *tableView1 = self.searchDisplayController.searchResultsTableView; for( UIView *subview in tableView1.subviews ) { if( [subview class] == [UILabel class] ) { UILabel *lbl = (UILabel*)subview; // sv changed to subview. lbl.text = @”没有结果”;}}}// Return YES to cause the search result table view to be reloaded.return YES;}
经过自己实际使用,发现一个问题,在第一次没有搜索到数据的情况下,上面代码中并没有执行if判断,也就是说没有符合条件的子视图,所以显示出来还是no results,而当第二次搜索可以正常显示『没有结果』。因此我猜想,在第一次要展示的时候,这个要展示no result的UILabel视图还没有添加到父视图上,是之后才创建的。之后又去网上搜索了一下找到如下解决办法:
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 *lbl = (UILabel *)v; [lbl setText:@"无结果"]; break; } } });
还是放到一样的代理方法中。经测试无问题。目前对于dispatch之类的东东还不是很熟悉,大概意思能看出来是推迟了方法的执行,保证执行的时候这个UILabel已经被添加到父视图上。(真的能万无一失的确保吗?)
- IOS:自定义UISearchDisplayController的cancel和no results
- UISearchDisplayController “No Results“ cancel修改
- 更改SearchBar的“No Results“标签和”Cancel“按钮
- UISearchDisplayController 去除“No Results”,“无结果” 的显示方法
- ios7 UISearchDisplayController cancel button title 自定义取消按键标题
- 自定义UISearchBar和UISearchDisplayController
- iOS UISearchBar 和 UISearchDisplayController的使用
- iOS UISearchBar和UISearchDisplayController
- How do I cover the “no results” text in UISearchDisplayController's searchResultTableView?
- iOS之UISearchDisplayController的使用
- iOS—自定义UISearchBar Cancel Button
- UISearchBar和 UISearchDisplayController的使用
- UISearchBar和 UISearchDisplayController的使用
- UISearchBar 和 UISearchDisplayController的使用
- UISearchBar 和 UISearchDisplayController的使用
- UISearchBar和 UISearchDisplayController的使用
- UISearchBar 和 UISearchDisplayController的使用
- UISearchBar 和 UISearchDisplayController的使用
- shell date 当前日期
- Oracle Hints
- vim中删除当前行后面所有的行
- warning no newline at the end of file
- Android执行打开文件(PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO)的总结
- IOS:自定义UISearchDisplayController的cancel和no results
- linux shell printf 宽字符
- Hint的常见错误使用方式
- SQL中order by 、group by 、having的用法区别
- bash与shell
- IOS推送通知的实现步骤
- strtok strsep
- ASM动态性能视图
- strtol,strtoul,strtod