简体   繁体   English

在tableview中搜索时如何更改文本“无结果”?

[英]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! 在没有结果的UITableView中搜索后,我想将“无结果”文本更改为“不匹配...”。但我找不到哪里。请帮忙!

在此输入图像描述

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". 循环浏览子视图并在其中寻找UILabel并更多地阐明我们正在寻找的子视图检查字符串/文本是否匹配“无结果”。
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. 如果在Info.plist中更改本地化本机开发区域,则字符串将替换为本机语言版本。 If you change to eg de it will be "Keine Ergebnisse". 如果您改为例如de将是“Keine Ergebnisse”。 This is tested on iOS 9. You could try to change the text via the internationalization. 这是在iOS 9上测试的。您可以尝试通过国际化来更改文本。 Maybe this is helpful for some people reading and searching for this thread. 也许这对于阅读和搜索此主题的人来说很有帮助。

related to: searchDisplayController: change the label "No Results" 相关: searchDisplayController:更改标签“No Results”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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