I am using the UISearchController alongside its UISearchBar. The UISearchController alongside its UITableView is placed inside a subview in my main view.
My goal is to lock the UISearchBar in its place so when its active, it does not move. Right now the following is happening:
I have searched this issue extensively and have tried the following such as:
self.searchController.hidesNavigationBarDuringPresentation = false, which just abruptly moves the search bar to the middle of the screen.definesPresentationContext = true, which does not change behaviorself.extendedLayoutIncludesOpaqueBars = true, which does not change behaviorUsing the
UIBarPositioningDelegatemethod mentioned here, which strangely cannot be translated to Swift because I cannot insert theAnyObject<UIBarPositioning>as it is in the Objective C version and still have it recognized as theoverridefunction
Any suggestion is appreciated.
Edit:
Here is the setup for the search items:
searchController.searchResultsUpdater = self searchController.dimsBackgroundDuringPresentation = false definesPresentationContext = true searchTableView.tableHeaderView = searchController.searchBar 1 Answers
Answers 1
Set your TableView's Style property to Plain in the Storyboard and use the SearchBar as the section header view. Along with the following code, I commented out tableView.tableHeaderView = searchController.searchBar in Apple's "Table Search with UISearchController" example and it worked fine.
override func numberOfSections(in tableView: UITableView) -> Int { return 1 } override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return searchController.searchBar.frame.size.height } override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { return searchController.searchBar } 

0 comments:
Post a Comment