我最近开始重写我的 iOS 应用程序以使用新的UISearchController和通用的故事板。我的应用程序可用于两种设备(iPhone和iPad),因此使用 更改通用情节提要UISplitViewController是一个很大的优势。
但遗憾的UISearchController是并没有按预期工作。我添加了UISearchController以下几行:
self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchBar.sizeToFit()
self.searchController.dimsBackgroundDuringPresentation = false
self.myTableView.tableHeaderView = self.searchController.searchBar
self.searchController.searchResultsUpdater = self
self.definesPresentationContext = true
我的控制器链是这样的:
UISplitViewController
UITabbarController (Master)
UINavigationController
UITableViewController
UINavigationController (Detail)
UINavigationController
UIViewController
问题是在 iPad 应用程序中UISearchBar,UINavigationBar. 但是,如果我切换选项卡并返回视图。UISearchBar是可见的。因此,在切换选项卡栏后,它会以某种方式正确重绘视图。在 iPhone 版本中,它会自动正确运行。
iPad 应用程序
第一次发射后UISearchBar,UINavigationBar

切换选项卡后UISearchBar正确显示

iPhone 应用程序
iPhone 应用程序在不更改选项卡的情况下正常工作..

我尝试了什么:
- 使用扩展边缘的不同设置
- 在 viewWillAppear 方法中添加 SearchController 因为我认为我可以通过稍后添加搜索控件来欺骗它