I am adding search bar on navigation bar, in iOS 7, using searchVC.displaysSearchBarInNavigationBar = YES;
,
which adds it on navigation bar as expected and works fine.
Now, I want to add a subview on navigation bar. When subview is added, I want to modify navigation bar, i.e. remove search bar from navigation bar and add some title on navigation bar. But, not able to remove Search Bar.
Tried a lot to remove search bar from navigation bar, but in vain.
The approaches I have followed so far are:
setting displaysSearchBarInNavigationBar propery to NO
searchVC.displaysSearchBarInNavigationBar = NO;
setting navigation title is not working too.
self.navigationItem.title = @"Some Title";
adding custom label view to titleView of navigationItem:
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 169, 44)]; lbl.backgroundColor = [UIColor clearColor]; lbl.textColor = [UIColor whiteColor]; lbl.textAlignment = NSTextAlignmentCenter; lbl.font = FontText_20; lbl.text = @"Draw Area"; self.navigationItem.titleView = lbl;
I used below code for adding search bar to navigation bar:
- (void)setupSearchBar {
// setup search bar
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 160, 44.0)];
searchBar.placeholder = @"Address / City / Zip";
searchBar.delegate = self;
searchBar.showsCancelButton = YES;
// setup search bar viewcontroller
searchVC = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchVC.delegate = self;
searchVC.searchResultsDataSource = self;
searchVC.searchResultsDelegate = self;
searchVC.displaysSearchBarInNavigationBar = YES;
}