Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default text to "No results" in UISearchDisplayController [duplicate]

I have a UISearchBar and a UISearchBarDisplayController set up by a xib. After a search with no result it says "No result" some lines down in the table. How to modify default text?

like image 894
Lars - Avatar asked Jan 18 '26 04:01

Lars -


2 Answers

You can also try this.

  1. In your search display controller's table view delegate/data source, suppress -numberOfRowsInSection: to minimum of 1.
  2. Then in your -cellForRowAtIndex: method, if your data source count is zero, change the label of the table view cell to something like "Searching..."
like image 142
chalcopyrite Avatar answered Jan 19 '26 18:01

chalcopyrite


@interface ClassName : UIViewController {
    UILabel                     *noResultLabel;
    UISearchDisplayController   *searchController;
}

@implementation ClassName

- (id) init {
    // bla bla bla bla
    // some more bla
    // setup your UISearchDisplayController and stuffz
    noResultLabel = nil;
}

- (void) changeNoResultsText:(NSString *)text {
    if (noResultLabel == nil) {
        for (id subview in searchController.searchResultsTableView.subviews) {
            if ([subview isKindOfClass:[UILabel class]]) {
                if ([((UILabel *)subview).text isEqualToString:@"No Results"]) {
                    if (noResultLabel == nil) noResultLabel = subview;
                }
            }
        }
    }

    if (noResultLabel != nil) noResultLabel.text = text;
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)bar { 
    [self changeNoResultsText:@"Searching..."];
}

- (BOOL) searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    [self changeNoResultsText:@"Searching full search..."];
    return YES;
}

@end
like image 31
EvilPenguin Avatar answered Jan 19 '26 16:01

EvilPenguin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!