How to Change Strings of "Cancel" Button, "No Results" Label in Uisearchbar of Uisearchdisplaycontroller

How can I change strings of Cancel button, No Results label in UISearchBar of UISearchDisplayController?

I solved it myself.

Cancel Button>

(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
[controller.searchBar setShowsCancelButton:YES animated:NO];
for (UIView *subview in [controller.searchBar subviews]) {
if ([subview isKindOfClass:[UIButton class]]) {
[(UIButton *)subview setTitle:@"_____" forState:UIControlStateNormal];
}
}
}

No Results Text>

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
if (!isChangedNoResults) {
if ([contactManager.filteredPeople count] == 0) {
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(changeNoResultsTextToKorean:) userInfo:nil repeats:YES];
}
}
}

I use timer and bool value.
If no timer, can not change text when "No Results" show first.

- (void)changeNoResultsTextToKorean:(NSTimer *)timer {
if (isChangedNoResults) {
[timer invalidate];
}
else {
for (UIView *subview in [self.searchDisplayController.searchResultsTableView subviews]) {
if ([subview isKindOfClass:[UILabel class]]) {
UILabel *targetLabel = (UILabel *)subview;
if ([targetLabel.text isEqualToString:@"No Results"]) {
NSLog(@"Changed!");
[targetLabel setText:@"_____"];
isChangedNoResults = YES;
[timer invalidate];
}
}
}
}
}

How to change default text to No results in UISearchDisplayController

@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

Swift: searchBar - how to change Cancel Button title

func searchDisplayControllerWillBeginSearch(controller: UISearchDisplayController) {
self.searchDisplayController?.searchBar.showsCancelButton = true
var cancelButton: UIButton
var topView: UIView = self.searchDisplayController?.searchBar.subviews[0] as UIView
for subView in topView.subviews {
if subView.isKindOfClass(NSClassFromString("UINavigationButton")) {
cancelButton = subView as UIButton
cancelButton.setTitle("Vazgeç", forState: UIControlState.Normal)
}
}
}

UISearchDisplayController No Results text

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.

How do I cover the no results text in UISearchDisplayController's searchResultTableView?

The easiest way to work around this is to return 1 in numberOfRowsInSection while the query is in progress and leave the dummy cell empty or set its hidden property to YES so it is not visible.

how to change the text no results when search in tableview?

Create a custom view with a label having text "No Results" and load it whenever your search query contain no value.

How to show No Results screen on UISearchDisplayController?

I guess, it would be enough to set sections number to 0 during search.



Related Topics



Leave a reply



Submit