How to remove the iOS 11 search bar from the view and update window

In xcode 9, when I put the search bar in my moves, the rest of the user interface is automatically reduced. When I try to remove the search bar from the view, I get black space instead of a fixed user interface. Used string: self.navigationItem.searchController = nil. I tried many things, but I don’t know how to fix the user interface after deleting the search bar. Only when I go to another view controller and back will the user interface come back again without a search bar. What am I missing here?

the code:

@IBAction func searchIconPressed(_ sender: UIBarButtonItem) { //ios 11 if #available(iOS 11.0, *) { if self.navigationItem.searchController == nil { self.navigationItem.searchController = self.searchController self.searchController.isActive = true } else { self.navigationItem.searchController?.isActive = false self.navigationItem.searchController = nil } } //when ios 9-10 else { if self.navigationItem.titleView == nil { self.navigationItem.titleView = self.searchController.searchBar self.searchController.isActive = true } else { self.navigationItem.titleView = nil } } } 

}

+7
ios11 xcode9
source share
2 answers

The answer is to delete the search bar and view the user interface again:

 self.navigationItem.searchController?.isActive = false let search = UISearchController(searchResultsController: nil) self.navigationItem.searchController = search self.navigationItem.searchController = nil 
+3
source share

And here for Objective C

 [self.navigationItem.searchController setActive:NO]; UISearchController *nilSearch = [[UISearchController alloc] initWithSearchResultsController:nil]; self.navigationItem.searchController = nilSearch; self.navigationItem.searchController = nil; 
0
source share

All Articles