2016-01-01 64 views
0

我以編程方式創建了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]; 

缺少什麼我在這裏?

+1

BarsSearchController.hidesNavigationBarDuringPresentation =是; –

回答

0
BarsSearchController.hidesNavigationBarDuringPresentation = YES; 
+0

實際上,對不起,這不起作用...默認值已經是YES,導航欄仍然顯示。其他想法? –

0

我有同樣的問題,解決它,我隱藏後退按鈕和背景在viewDidLoad中:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.navigationItem.hidesBackButton = YES; 
    [[[self navigationController] navigationBar] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; 
    [[[self navigationController] navigationBar] setShadowImage:[UIImage new]]; 
    [[[self navigationController] navigationBar] setTranslucent:YES]; 
} 

和我隱藏的導航欄在viewDidAppear:

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    [[self navigationController] setNavigationBarHidden:YES]; 
} 
相關問題