iOS,Swift 3 – 当我从Detail View返回后点击Cancel时,UISearchBar消失

我有一个containerView的tableView。 以编程方式向其添加了一个searchBar。 一切工作正常,除了情况:当我点击一个单元格,而tableView是由searchBar过滤,然后我从detailView返回(这是通过推塞格呈现),然后我closuressearchBar(取消button) ,那么searchBar就会消失。 神秘的是,当我在控制台上debugging时,searchBar对象仍然存在,它仍然是tableView的headerView …任何人有一个想法,什么可能会导致这个问题,以及如何解决它?

这是我的相关代码:

在viewDidLoad中:

self.searchController.searchResultsUpdater = self self.searchController.delegate = self self.searchController.dimsBackgroundDuringPresentation = false self.searchController.hidesNavigationBarDuringPresentation = false self.searchController.definesPresentationContext = false self.tableView.tableHeaderView = self.searchController.searchBar 

searchControllerDelegate:

 func willPresentSearchController(_ searchController: UISearchController) { if let mpvc = self.parent as? MyPulleyViewController { mpvc.navigationController?.navigationBar.isTranslucent = true } } func willDismissSearchController(_ searchController: UISearchController) { if let mpvc = self.parent as? MyPulleyViewController { mpvc.navigationController?.navigationBar.isTranslucent = false } } 

(myPulleyViewController是包含containerView的VC,self是containerView的VC)

在IB上,mpvc设置为“延伸边缘”:在“不透明条”下

谢谢你的帮助!

我面临同样的问题,我认为这是iOS的问题,我通过使查看控制器的search结果:

  let searchVC = mainStoryboard.instantiateViewController(withIdentifier: identifier) as! SearchResultViewController let searchController = UISearchController(searchResultsController: searchVC) searchController.searchResultsUpdater = searchVC 

它工作正常。