search

Home  >  Q&A  >  body text

ios - UISearchDisplayController 去掉背景中的no results文字

巴扎黑巴扎黑2767 days ago574

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 16:34:54

    Place the following methods in the UISearchBarDelegate proxy method or UISearchDisplayControllerdelegate proxy method:

    1) If you want to change this character and replace it with the string you want, you can try:

      for (UIView *subView in            self.searchDisplayController.searchResultsTableView.subviews) {
        if ([subView isKindOfClass:NSClassFromString(@"UILabel")]) {
            UILabel *label =(UILabel *)subView;
            label.text = @"自定义字符串";
        }
    }

    2) If you simply want to cover this text, the best method I have ever used is:

      for (UIView *subView in self.searchDisplayController.searchResultsTableView.subviews) {
        if ([subView isKindOfClass:NSClassFromString(@"UILabel")]) {
            UILabel *label =(UILabel *)subView;
         //自定义一个View
            CGFloat ViewWidth = [UIScreen mainScreen].bounds.size.width*0.64;
            CGFloat ViewHeight = ViewWidth*0.75;
            tempNoResultView = [[UIView alloc]init];
            tempNoResultView.size = CGSizeMake(ViewWidth, ViewHeight);
            tempNoResultView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, heightToTop);
            tempNoResultView.backgroundColor = [UIColor whiteColor];
            [label addSubview:_tempNoResultView];
        }
    }
    //相当于遍历出这个label,用一个View把“No Result”遮盖掉。只有这个方法虽然很low但是works well,用其他的方法并不稳定,因为并不建议修改这些东西而且UISearchDisplayController是个坑,这也是为什么后来苹果放弃UISearchDisplayController的原因。

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 16:34:54

    It will appear when there is no data, just set a dummy cell.

    reply
    0
  • PHPz

    PHPz2017-04-17 16:34:54

    When there is no data, set a blank cell. . Deal with it this way. .

    reply
    0
  • Cancelreply