我在iOS9中遇到这种奇怪的行为,当ViewController第一次出现时,范围栏在UISearchBar后面可见:
按下“搜索”后,UISearchBar按预期运行(UISearchBar移动到顶部,下面的范围栏)。完成搜索或点击取消后,它将从头开始返回到我想要的状态:
在viewDidLoad方法中,我按如下方式初始化UISearchController:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchController.searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
[self.searchController.searchBar sizeToFit];
self.definesPresentationContext = YES;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.scopeButtonTitles = @[[self titleForScopeButton:ScopeButtonIdNameDesc],
[self titleForScopeButton:ScopeButtonIP]];
有什么想法吗?
答案 0 :(得分:0)
我还没有在那个应用程序上工作过,忘记了我在appDelegate的didFinishLaunchingWithOptions中设置了UISearchBar的整体外观。
[[UISearchBar appearance] setSearchBarStyle:UISearchBarStyleMinimal];
[[UISearchBar appearance] setBackgroundColor:[PCConstantsGUI tintColor]];
[[UISearchBar appearance] setTintColor:[PCConstantsGUI tintColor]];
造成渲染问题的罪魁祸首是“UISearchBarStyleMinimal”,在我不得不用UISearchController替换已弃用的UISearchDisplayController之前看起来很漂亮。