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

4 回答 4

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;
    }
}
于 2014-09-10T13:15:44.217 回答
2

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

于 2012-12-30T13:45:32.317 回答
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.

于 2012-12-31T10:22:32.847 回答
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"

于 2015-12-08T01:27:15.873 回答