- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
searchDisplayController.searchBar.backgroundColor = [UIColor whiteColor];
searchDisplayController.searchBar.showsCancelButton = YES;
//定义取消按钮
/*
*ios7与ios6方法不同
*/
if (IOS7_OR_LATER) {
for (id searchbutton in mySearchBar.subviews)
{
UIView *view = (UIView *)searchbutton;
UIButton *cancelButton = (UIButton *)[view.subviews objectAtIndex:2];
cancelButton.enabled = YES;
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];//文字
break;
}
}else
{
for(id cancelButton in [searchDisplayController.searchBar subviews])
{
if([cancelButton isKindOfClass:[UIButton class]])
{
UIButton *btn = (UIButton *)cancelButton;
[btn setTitle:@"取消" forState:UIControlStateNormal];
}
}
}
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
//去除 No Results 标签
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.001);
dispatch_after(popTime, dispatch_get_main_queue(), ^{
for (UIView *subview in controller.searchResultsTableView.subviews) {
if ([subview isKindOfClass:[UILabel class]] && ([[(UILabel *)subview text] isEqualToString:@"No Results"] || [[(UILabel *)subview text] isEqualToString:@"无结果"])) {
[subview removeFromSuperview];
break;
}
}
});
return YES;
}
IOS在UISearchDisplayController里定义取消按钮和去掉No Result
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 小学语文修改病句的方法 修改病句是小学语文考试中常见的题型,在修改病句之前,我们应该清晰的了解有哪些病句现象,下面...