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

浪子不回头ぞ 提交于 2019-12-19 20:00:08

问题


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:

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

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?


回答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:



来源:https://stackoverflow.com/questions/30458336/my-uisearchbar-in-uisearchcontroller-disappear-when-i-start-searching-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!