ios - UISearchDisplayController 去掉背景中的no results文字
巴扎黑
巴扎黑 2017-04-17 16:32:54
0
3
539
巴扎黑
巴扎黑

répondre à tous(3)
Peter_Zhu

将以下方法放在UISearchBarDelegate代理方法或者UISearchDisplayControllerdelegate代理方法中:

1)如果你想改掉这个字符,换为自己想要的字符串的话可以试试:

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

2) 如果单纯想覆盖掉这段文字的话,我用过的最好的方法是:

  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的原因。
刘奇

没有数据的时候会出现,设置一个dummy cell即可。

PHPzhong

无数据时,设置一个空白 cell。。这样处理。。

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!