天蓬老师2017-04-17 16:34:54
Place the following methods in the UISearchBarDelegate proxy method or UISearchDisplayControllerdelegate proxy method:
1) If you want to change this character and replace it with the string you want, you can try:
for (UIView *subView in self.searchDisplayController.searchResultsTableView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UILabel")]) {
UILabel *label =(UILabel *)subView;
label.text = @"自定义字符串";
}
}
2) If you simply want to cover this text, the best method I have ever used is:
for (UIView *subView in self.searchDisplayController.searchResultsTableView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UILabel")]) {
UILabel *label =(UILabel *)subView;
//自定义一个View
CGFloat ViewWidth = [UIScreen mainScreen].bounds.size.width*0.64;
CGFloat ViewHeight = ViewWidth*0.75;
tempNoResultView = [[UIView alloc]init];
tempNoResultView.size = CGSizeMake(ViewWidth, ViewHeight);
tempNoResultView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, heightToTop);
tempNoResultView.backgroundColor = [UIColor whiteColor];
[label addSubview:_tempNoResultView];
}
}
//相当于遍历出这个label,用一个View把“No Result”遮盖掉。只有这个方法虽然很low但是works well,用其他的方法并不稳定,因为并不建议修改这些东西而且UISearchDisplayController是个坑,这也是为什么后来苹果放弃UISearchDisplayController的原因。