【问题标题】:UISearchDisplayController "No Results" text [duplicate]UISearchDisplayController“无结果”文本[重复]
【发布时间】:2011-12-09 14:41:18
【问题描述】:

可能重复:
How can I change strings of “Cancel” button, “No Results” label in UISearchBar of UISearchDisplayController?

在我的 UISearchDisplayController 中,当没有可用结果时,我想更改出现在 searchResultsTableView 中的“无结果”文本的字体。

我该怎么做?

【问题讨论】:

    标签: iphone ios uisearchdisplaycontroller


    【解决方案1】:

    您的问题可能与How can I change strings of "Cancel" button, "No Results" label in UISearchBar of UISearchDisplayController?重复

    这是对那里给出的答案的修改:

    -(BOOL)searchDisplayController:(UISearchDisplayController *)controller 
            shouldReloadTableForSearchString:(NSString *)searchString {
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.001);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            for (UIView* v in self.sbc.searchResultsTableView.subviews) {
                if ([v isKindOfClass: [UILabel class]] && 
                        [[(UILabel*)v text] isEqualToString:@"No Results"]) {
                    // .. do whatever you like to the UILabel here ..
                    break;
                }
            }
        });
        return YES;
    }
    

    基本上,您要求做的只是访问显示“无结果”文本的 UILabel。没有官方的方法可以做到这一点。正如该页面所建议的,解决方法是查找 UILabel(通过枚举搜索结果表的所有子视图)并对其进行修改。我一般不会鼓励这种事情,但我发现 Apple 拒绝提供官方方式来解决这个“无结果”标签是非常令人讨厌的,所以在这场特殊的斗争中没有任何保留。

    【讨论】:

    • 如果设备语言不是英语,这将不起作用。
    • @AlastairStuart 好点。以刀为生的,死于刀下;我这是一个卑鄙的解决方法。 Apple 确实需要让我们以某种官方方式对其进行自定义。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多