这就是我设置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)
}
这是我初始化UISearchController
时的注意事项:
这就是我开始在UISearchBar中输入时的样子:
为什么我的搜索栏会消失?
这非常有趣,因为现在当我停止应用程序时,你可以看到它确实在那里:-)那么为什么它不可见?
答案 0 :(得分:1)
我做了一些测试并找到了一种方法:
UISearchBar肯定必须插入到包装器中:
@IBOutlet weak var wrapperView: UIView!
...
wrapperView.addSubview(searchController.searchBar)
结果如下: