【问题标题】:How to change default text to "No results" in UISearchDisplayController [duplicate]如何在 UISearchDisplayController 中将默认文本更改为“无结果”[重复]
【发布时间】:2013-07-18 13:51:04
【问题描述】:

我有一个由 xib 设置的 UISearchBar 和一个 UISearchBarDisplayController。 在没有结果的搜索之后,它在表格中的一些行中显示“没有结果”。 如何修改默认文本?

【问题讨论】:

  • 7 个问题,您没有将任何问题标记为已接受?您之前的任何问题都得到充分回答了吗?
  • 我的 7 个问题中有 2 个给了我帮助。我写了反馈并将答案标记为已接受。我不知道为什么它说 0%
  • 我认为在反馈中标记为已接受就足够了,但我现在知道如何在左边距中标记符号以使其变为绿色。

标签: iphone xcode uisearchbar uisearchdisplaycontroller


【解决方案1】:

你也可以试试这个。

  1. 在您的搜索显示控制器的表格视图委托/数据源中,将 -numberOfRowsInSection: 抑制为 1。
  2. 然后在您的 -cellForRowAtIndex: 方法中,如果您的数据源计数为零,请将表格视图单元格的标签更改为“正在搜索...”之类的内容

【讨论】:

    【解决方案2】:
    @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
    

    【讨论】:

    • 不幸的是,这可能仅在语言环境为英语时才有效。
    • 是的,这仅适用于英语,您需要更改“无结果”以处理其他语言。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 2020-11-30
    • 2017-11-12
    相关资源
    最近更新 更多