UISearchDisplayController “No Results” text [duplicate]

大兔子大兔子 提交于 2019-12-03 07:53:05

问题


Possible Duplicate:
How can I change strings of “Cancel” button, “No Results” label in UISearchBar of UISearchDisplayController?

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

How can I do this?


回答1:


You question may be a duplicate of How can I change strings of "Cancel" button, "No Results" label in UISearchBar of UISearchDisplayController?

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;
}

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.



来源:https://stackoverflow.com/questions/8447086/uisearchdisplaycontroller-no-results-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!