I am showing searchbar in home page. When I push a UIViewController then get back to home page, the searchbar become hidden.
here is my code
func setupSearch(){
searchController = UISearchController(searchResultsController: resultsTableController)
searchController.searchResultsUpdater = self
searchController.searchBar.autocapitalizationType = .none
searchController.searchBar.searchTextField.placeholder = "Enter a search term...".localized()
searchController.searchBar.returnKeyType = .search
// Place the search bar in the navigation bar.
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
// searchController.hidesNavigationBarDuringPresentation = false
// Monitor when the search controller is presented and dismissed.
searchController.delegate = self
// Monitor when the search button is tapped, and start/end editing.
searchController.searchBar.searchTextField.delegate = self
/** Specify that this view controller determines how the search controller is presented.
The search controller should be presented modally and match the physical size of this view controller.
*/
definesPresentationContext = true
}
Related
I have a UISearchBar embedded in the NavigationItem, like so:
let search = UISearchController(searchResultsController: nil)
search.searchBar.delegate = self
search.hidesNavigationBarDuringPresentation = false
search.definesPresentationContext = false
search.delegate = self
navigationItem.searchController = search
And I also have a collectionView.
When I push a viewController from the collectionview, and then go back, I can't see the UISearchBar anymore.
Any way of fixing this?
Left side displays my app in the iPhone 7 simulator. Right side is the app as displayed in my device. When tapping in the search bar, the navbar sildes up but then slides back down as showing in the image with the "What is this?" text.
The code for my search controller is as follows and it is being called in viewDidLoad.
//MARK: - Search Controller
func configureSearchController() {
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
// to receive updates
searchController.searchResultsUpdater = self
// Set up searchbar of search controller
searchController.searchBar.scopeButtonTitles = ["All", "Something", "Something"]
searchController.searchBar.delegate = self
// add the searchbar to the tableview
tableView.tableHeaderView = searchController.searchBar
// hack to fix ocassional bugs
searchController.searchBar.sizeToFit()
}
I have a UINavigationController that has a UISearchController assigned to the navigationItem's searchController. Inside the view I have a UICollectionView. The search bar displays in the navigation bar, but when I scroll, the navigation bar automatically hides. Can I stop this from happening?
let searchController = UISearchController(searchResultsController: recentSearchesViewController)
searchController.searchResultsUpdater = recentSearchesViewController
searchController.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
navigationItem.searchController = searchController
You have to set :
navigationItem.hidesSearchBarWhenScrolling = false
I currently have my UISearchController set up so it is presented over the nav bar once the search icon is clicked.
var searchController: UISearchController!
#IBAction func searchMe(sender: UIBarButtonItem) {
// Create the search results view controller and use it for the `UISearchController`.
let searchResultsController = storyboard!.instantiateViewControllerWithIdentifier(SearchResultsViewController.StoryboardConstants.identifier) as! SearchResultsViewController
// Create the search controller and make it perform the results updating.
searchController = UISearchController(searchResultsController: searchResultsController)
searchController.searchResultsUpdater = searchResultsController
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.tintColor = Colors.blue
searchController.searchBar.barTintColor = UIColor.whiteColor()
// Present the view controller.
presentViewController(searchController, animated: true, completion: nil)
}
I am using a different searchResultsController than the current table view to display results. The problem is that when a cell is selected in the searchResultsController a segue is performed to a new view controller (the users profile) and there is no navigation bar.
I need a back button to appear to take the user back to the searchResultsController. I have tried a bunch of different segues, setting the nav bars on the storyboard but nothing seems to work. My initial thought was to make this line of code:
searchController = UISearchController(searchResultsController: searchResultsController)
point to a nav controller with searchResultsController as its root view controller but I had no luck. Any help is great! Thank you!
I'm trying out UISearchController for iOS 8 right now. When I click the cell, it will push the segue and show another view controller. However, the search controller/bar is still there on the next controller. Also, I notice that the status bar background is white, while it should be grey as the searchBar background color is grey. Is there anything that I miss?
This is the codes that I used to initialise the search controller
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.sizeToFit()
tableView.tableHeaderView = searchController.searchBar
}
Screenshot:
Manual stop UISearchController in prepareForSegue
searchController.active = false
Or add this in viewDidLoad
searchController.definesPresentationContext = true