我已经使用UISearchBar创建了一个UITableView Controller作为Table的标题。
然后我将这个View Controller嵌入到UINavigationController中,作为根视图控制器。
现在,当我点击搜索栏时,SearchBar似乎消失并显示白屏。键盘出现,但没有搜索栏。 表视图可以滚动,但搜索栏已经消失了。
当我在没有导航控制器的情况下实现这个UITableViewController 时,它完美地运行。但是关于导航控制器的一些事情正在酝酿中。
答案 0 :(得分:4)
我有同样的问题,有时会发生,特别是对于少量行(小于50)的表视图。 看来searchBar是从视图层次结构中删除的,恰好来自容器视图,它是UISearchControllerView的子视图。
我找到了一种解决方法,可以手动将搜索栏添加回UISearchControllerView容器子项的子视图。这是在委托函数(来自UISearchControllerDelegate)didPresentSearchController中实现的:
func didPresentSearchController(searchController: UISearchController) {
if searchController.searchBar.superview == nil {
for searchCtrlChildView in searchController.view.subviews {
if searchCtrlChildView.frame.origin == CGPoint(x: 0, y: 0) { //Discriminate if by chance there was more than one subview
searchCtrlChildView.addSubview(searchController.searchBar)
break
}
}
}
}
我还向Apple提交了雷达,因为它未在iOS 8.4中修复
答案 1 :(得分:0)
我的viewController也嵌入了NavigationController
我的代码(希望有所帮助):
class myTableViewController: UITableViewController,UISearchResultsUpdating,UISearchControllerDelegate,UISearchBarDelegate
override func viewDidLoad() {
super.viewDidLoad()
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()