2017-08-07 28 views
0

我在containerView中有一個tableView。以編程方式將searchBar添加到它。一切正常,除了案件:當我點擊一個單元格,而tableView是由searchBar過濾,然後我從detailView返回(通過push segue呈現),然後我關閉searchBar(取消按鈕) ,那麼searchBar就會消失。 神祕的是,當我在控制檯上調試它時,searchBar對象仍然存在,它仍然是tableView的headerView ... 任何人都有一個想法,什麼會導致這個問題,以及如何解決它?iOS,Swift 3 - 當我從Detail View返回後點擊Cancel時,UISearchBar消失

這裏是我的相關代碼:

在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,自我是containerView的VC)

在IB上,mpvc被設置爲Extend edges:在不透明酒吧

感謝您的任何幫助!

回答

1

我面臨同樣的問題,我覺得這是iOS的問題,我固定它通過使視圖 - 控制搜索結果:

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

,它工作正常。

相關問題