我以編程方式創建了UISearchController並將其添加到我的UIView A.我也在同一個UIView中有一個UITableView。我使用UISearchController來搜索我的UITableView。當你點擊一個單元格時,UIView B被推送。 UIView A和UIView B都將UINavigationBar設置爲HIDDEN。 當我簡單地點擊一個沒有搜索的UITableViewCell時,一切都完全發生,並且UIView B在沒有UINavigationBar的情況下顯示。iOS - 在UISearchController處於活動狀態時顯示導航欄
但是,當我使用UISearchController進行搜索並單擊UITableViewCell時,UINavigationBar顯示在UIView B上,即使我將它設置爲隱藏在viewDidAppear方法中。
這裏是我的代碼:
BarsSearchController = [[UISearchController alloc] initWithSearchResultsController:nil];
BarsSearchController.searchResultsUpdater = self;
BarsSearchController.dimsBackgroundDuringPresentation = NO;
BarsSearchController.searchBar.delegate = self;
BarsSearchController.searchBar.barTintColor = [UIColor whiteColor];
BarsSearchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
[searchBarView addSubview:BarsSearchController.searchBar];
[searchBarView addConstraint:[NSLayoutConstraint constraintWithItem:BarsSearchController.searchBar
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:searchBarView
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0.0]];
[searchBarView addConstraint:[NSLayoutConstraint constraintWithItem:BarsSearchController.searchBar
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:searchBarView
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant:0.0]];
[searchBarView addConstraint:[NSLayoutConstraint constraintWithItem:BarsSearchController.searchBar
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:searchBarView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0.0]];
[searchBarView addConstraint:[NSLayoutConstraint constraintWithItem:BarsSearchController.searchBar
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:searchBarView
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0.0]];
[searchBarView layoutIfNeeded];
self.definesPresentationContext = YES;
[BarsSearchController.searchBar sizeToFit];
缺少什麼我在這裏?
BarsSearchController.hidesNavigationBarDuringPresentation =是; –