UISplitViewController + UISearchController显示详细搜索

时间:2015-08-25 18:58:49

标签: ios uisplitviewcontroller ios9 uisearchcontroller

在iPhone上,我们有一个UISplitViewController。主人在tableHeaderView中有一个搜索控制器。如果我们有一个活动的搜索,当我们切换到细节时,搜索栏仍会显示在详细信息页面上。我们如何摆脱它。

以下是在tableview中添加搜索栏的代码

    self.searchController.searchResultsUpdater = self
    self.searchController.hidesNavigationBarDuringPresentation = false
    self.searchController.dimsBackgroundDuringPresentation = false
    self.searchController.definesPresentationContext = true
    self.searchController.searchBar.sizeToFit()
    self.tableView.tableHeaderView = searchController.searchBar

我尝试在prepareForSeque

中使用resignFirstResponder
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "Show Event Filter" {
        self.sendEventWithCategory(kAnalyticsCategoryUI_Action, withAction: kAnalyticsActionList_Select, withLabel: "Select filter", withValue: nil, forModuleNamed: self.module?.name)
        let navigationController = segue.destinationViewController as! UINavigationController
        let detailController = navigationController.viewControllers[0] as! EventsFilterViewController
        detailController.eventModule = self.eventModule
        detailController.hiddenCategories = self.hiddenCategories
        detailController.module = self.module
        detailController.delegate = self
    } else if segue.identifier == "Show Detail" {
        let detailController = (segue.destinationViewController as! UINavigationController).topViewController as! EventsDetailViewController
        let event = fetchedResultsController.objectAtIndexPath(self.tableView.indexPathForSelectedRow!) as! Event
        detailController.event = event
        detailController.module = self.module
    }
    self.searchController.searchBar.resignFirstResponder()
}

我也尝试删除segue,只需在didSelectRowAtIndexPath中调用resignFirstResponder。似乎resignFirstResponder没有做任何事情。使用Xcode 7 beta 6(在测试版5上发现)。

1 个答案:

答案 0 :(得分:0)

我遇到了完全相同的问题。通过在viewDidLoad上将以下代码添加到我的主视图控制器来解决此问题: self.definesPresentationContext = true