UISearchDisplayController“没有结果”文本

问题描述:


可能重复:

如何更改“取消”按钮,&ndquo;没有结果” UISearchDisplayController的UISearchBar中的标签?

在我的UISearchDisplayController中,我想更改当没有结果可用时,searchResultsTableView中显示的No Results文本的字体。

In my UISearchDisplayController, I want to change the font of the "No Results" text that appears in the searchResultsTableView when no results are available.

我该怎么做?

您的问题可能与如何更改取消字符串?按钮,无结果 UISearchDisplayController的UISearchBar中的标签?

这里给出了答案的修改:

Here's a modification of the answer given there:

-(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.sbc.searchResultsTableView.subviews) {
            if ([v isKindOfClass: [UILabel class]] && 
                    [[(UILabel*)v text] isEqualToString:@"No Results"]) {
                // .. do whatever you like to the UILabel here ..
                break;
            }
        }
    });
    return YES;
}

基本上你要做的就是访问UILabel显示无结果文本。没有正式的方法可以做到这一点。该页面上建议的解决方法是查找UILabel(通过枚举搜索结果表的所有子视图)并对其进行修改。我一般不能鼓励这种事情,但我发现Apple拒绝提供正式的方法来解决这个无结果标签是彻头彻尾的讨厌,所以在这场特殊的战斗中没有禁止。

Basically what you're asking to do is simply to access the UILabel that is displaying the "No Results" text. There is no official way to do that. The workaround, as suggested on that page, is to look for the UILabel (by enumerating all the subviews of the search results table) and modify it. I generally can't encourage this sort of thing, but I find Apple's refusal to supply an official way to grapple with this "No Results" label to be downright obnoxious, so no holds are barred in this particular fight.