5

This is how I setup my UIsearchController

private func setupSearchController() {
    let searchResultsController = storyboard!.instantiateViewControllerWithIdentifier(DBSearchOptionControllerIdentifier) as! DBSearchOptionController

    searchController = UISearchController(searchResultsController: searchResultsController)

    let frame = searchController.searchBar.frame
    searchController.searchBar.frame = CGRectMake(0, 50, view.bounds.size.width, 44.0)
    searchController.searchResultsUpdater = self
    view.addSubview(searchController.searchBar)
    searchController.searchBar.text = "mmm"
    view.bringSubviewToFront(searchController.searchBar)
    searchController.searchBar.bringSubviewToFront(view)

}

This is how it looks after I initialise UISearchController:

enter image description here

This is how it looks when I start typing in UISearchBar:

enter image description here

Why my search bar disappear?

This is very interesting, because now when I stop the app, you can see, that it is there, indeed:-) So why it is not visible?

enter image description here

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

1 Answers1

1

I made some testing and found a way:

UISearchBar definitely must be inserted into wrapper:

@IBOutlet weak var wrapperView: UIView!

...

wrapperView.addSubview(searchController.searchBar)

The result is following:

enter image description here

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358