Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchDisplayController "No Results" text [duplicate]

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?

like image 696
Collin Avatar asked Dec 09 '11 14:12

Collin


1 Answers

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.

like image 163
matt Avatar answered Oct 22 '22 05:10

matt