Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My UISearchBar in UISearchController disappear when I start searching. Why?

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

like image 264
Bartłomiej Semańczyk Avatar asked Nov 10 '22 12:11

Bartłomiej Semańczyk


1 Answers

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

like image 174
Bartłomiej Semańczyk Avatar answered Jan 04 '23 03:01

Bartłomiej Semańczyk