【发布时间】:2016-01-01 21:46:14
【问题描述】:
我以编程方式创建了一个 UISearchController 并将其添加到我的 UIView A。我在同一个 UIView 中也有一个 UITableView。我使用 UISearchController 来搜索我的 UITableView。当你点击一个单元格时,UIView B 会被推送。 UIView A 和 UIView B 都将 UINavigationBar 设置为 HIDDEN。 当我在没有搜索的情况下直接点击 UITableViewCell 时,一切都很完美,并且 UIView B 显示时没有 UINavigationBar。
但是当我使用 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 = YES;
标签: ios objective-c uinavigationbar uisearchcontroller