[英]iOS - navigation bar displayed when UISearchController is active
I programatically created a UISearchController and added it to my UIView A. I also have a UITableView in the same UIView. 我以编程方式创建了一个UISearchController并将其添加到我的UIView A中。同一UIView中也有一个UITableView。 I use UISearchController to search through my UITableView.
我使用UISearchController来搜索我的UITableView。 When you click on a cell, UIView B gets pushed.
当您单击一个单元格时,UIView B被推入。 Both UIView A and UIView B have UINavigationBar set to HIDDEN.
UIView A和UIView B都将UINavigationBar设置为HIDDEN。 When I simply click on a UITableViewCell WITHOUT searching, everything happens perfectly, and UIView B is displayed without UINavigationBar.
当我简单地单击一个UITableViewCell而不进行搜索时,一切都会很好地进行,并且显示的UIView B没有UINavigationBar。
But when I am searching using the UISearchController and I click on a UITableViewCell, the UINavigationBar is displayed on UIView B, even though I set it to hidden in the viewDidAppear method. 但是,当我使用UISearchController进行搜索并单击UITableViewCell时,即使我在viewDidAppear方法中将其设置为隐藏,UINavigationBar也会显示在UIView B上。
Here is my code: 这是我的代码:
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];
What am I missing here? 我在这里想念什么?
BarsSearchController.hidesNavigationBarDuringPresentation = YES;
I have the same problem, to fix it, I hide back button and background in viewDidLoad : 我有同样的问题,要解决,我在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];
}
and I hide navigationBar in viewDidAppear : 我将viewBar隐藏在viewDidAppear中:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[self navigationController] setNavigationBarHidden:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.