4

After search in UITableView with no result, I want to change the text "No results" to "Not Match...".But I can't find where.Please help!

enter image description here

Here is some code:

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
 if ([self.webSearchData count] == 0) {

            for (UILabel *label in self.searchTable.subviews) {
                if (label.text = @"No Results") {
                    label.text = @"Not Match";
                }
            }
}
}
LE SANG
  • 10,955
  • 7
  • 59
  • 78
  • 2
    There is no supported way to change it. However check this out http://stackoverflow.com/questions/3451945/uitableview-change-no-results-message – Breakpoint Dec 30 '12 at 10:56

4 Answers4

4

It's an old thread, but for anyone having the same issue, try something like this.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == _searchDisplayController.searchResultsTableView) {
        if (_searchResults.count == 0) {
            for (UIView *view in tableView.subviews) {
                if ([view isKindOfClass:[UILabel class]]) {
                    ((UILabel *)view).text = @"YOUR_TEXT";
                }
            }
        }

        return _searchResults.count;
    } else {
        return (_items.count == 0) ? 0 : _items.count;
    }
}
pixelsize
  • 488
  • 5
  • 5
2

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

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • Maybe only this way.I think someone know the way to set directly before I ask this question. – LE SANG Dec 30 '12 at 16:13
  • I am not into ios but, so dont know in detail. but as I looked for the aswer, it said apple doesn't provide that. So if you want to implement, either you go with the above go extend the feature/class through which "No Results" are shown. – Anoop Vaidya Dec 30 '12 at 16:16
2

Loop through the subviews and seek for the UILabel in it and to clarify more that its the subview that we are seeking for check the string/text matches "No Results".
if it matches then simply change the text to "No Match".

or

or show up a single row with a blank cell when you're still waiting for the user to press the search button.

yunas
  • 4,143
  • 1
  • 32
  • 38
  • Could you please make clear? I can't find which views these subviews belong to. – LE SANG Dec 31 '12 at 11:42
  • you have to iterate through the "searchResultsTableView's" subviews to search the view containing the text "No Results" – yunas Dec 31 '12 at 15:00
  • I update some above code.When assign label.text = @"Not Match", it change the searchBar.text, not the view label in the searchTable.Please check my update. – LE SANG Dec 31 '12 at 17:06
0

If you change your localization native development region in your Info.plist the string will be replaced with a native language version. If you change to e.g. de it will be "Keine Ergebnisse". This is tested on iOS 9. You could try to change the text via the internationalization. Maybe this is helpful for some people reading and searching for this thread.

related to: searchDisplayController: change the label "No Results"

Community
  • 1
  • 1
REISWOLF
  • 67
  • 5