简体   繁体   中英

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

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!

在此输入图像描述

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

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

使用带有文本“无结果”的标签创建自定义视图,并在搜索查询不包含任何值时加载它。

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.

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 eg 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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM