如何在UISearchDisplayController中将默认文本更改为"无结果"

Lar*_*s - 2 iphone xcode uisearchbar uisearchdisplaycontroller

我有一个UISearchBar和一个UISearchBarDisplayController由xib设置.在没有结果的搜索之后,它在表格中显示"无结果".如何修改默认文字?

cha*_*ite 8

你也可以试试这个.

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


小智 5

@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
Run Code Online (Sandbox Code Playgroud)

  • 不幸的是,如果语言环境是英语,这可能只会起作用. (4认同)