消失在UINavigationController中的TableViewController中的UISearchController

我做了一个UITableView控制器与UISearchBar作为表头。

然后我把这个View Controller作为根视图控制器embedded到一个UINavigationController中。

现在,当我点击search栏,SearchBar似乎消失,并显示一个白色的屏幕。 键盘出现,但没有search栏。 表视图可以滚动,但search栏已经消失。

当我没有导航控制器实现这个UITableViewController,它完美的作品。 但是关于导航控制器的一些事情正在让所有的事情都发生。

我遇到了同样的问题,特别是对于less数行(小于50)的表视图。 它看起来是从视图层次结构中删除searchBar,正是从UISearchControllerView的子容器视图中删除。

我find了一种解决方法,手动添加回search栏作为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 } } } } 

我也向苹果公司提交了一个雷达,因为它在iOS 8.4中没有修复

检查我有我的searchBar它在viewDidLoad的方式

我也有我的viewControllerembedded在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 })()