如何更改“取消”字符串?按钮,“无结果” UISearchDisplayController的UISearchBar中的标签? [英] How can I change strings of "Cancel" button, "No Results" label in UISearchBar of UISearchDisplayController?

查看:68
本文介绍了如何更改“取消”字符串?按钮,“无结果” UISearchDisplayController的UISearchBar中的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在UISearchDisplayController的UISearchBar中更改取消按钮,无结果标签
的字符串?

How can I change strings of "Cancel" button, "No Results" label in UISearchBar of UISearchDisplayController ?

请帮助我!

推荐答案

我自己解决了。

取消按钮>

(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    [controller.searchBar setShowsCancelButton:YES animated:NO];
    for (UIView *subview in [controller.searchBar subviews]) {
        if ([subview isKindOfClass:[UIButton class]]) {
            [(UIButton *)subview setTitle:@"_____" forState:UIControlStateNormal];
        }
    }
}

无结果文字>

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
    if (!isChangedNoResults) {
        if ([contactManager.filteredPeople count] == 0) {
            [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(changeNoResultsTextToKorean:) userInfo:nil repeats:YES];
        }
    }
}

我使用计时器和bool值。
如果没有计时器,则在第一次显示无结果时无法更改文本。

I use timer and bool value. If no timer, can not change text when "No Results" show first.

- (void)changeNoResultsTextToKorean:(NSTimer *)timer {
    if (isChangedNoResults) {
        [timer invalidate];
    }
    else {
        for (UIView *subview in [self.searchDisplayController.searchResultsTableView subviews]) {
            if ([subview isKindOfClass:[UILabel class]]) {
                UILabel *targetLabel = (UILabel *)subview;
                if ([targetLabel.text isEqualToString:@"No Results"]) {
                    NSLog(@"Changed!");
                    [targetLabel setText:@"_____"];
                    isChangedNoResults = YES;
                    [timer invalidate];
                }
            }
        }
    }
}

这篇关于如何更改“取消”字符串?按钮,“无结果” UISearchDisplayController的UISearchBar中的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆