简体   繁体   中英

self.definesPresentationContext = true: leads to black screen?

    let searchController = UISearchController(searchResultsController: nil)

override func viewDidLoad() {
    super.viewDidLoad()

    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false

  //  searchController.definesPresentationContext = true
    self.definesPresentationContext = true

When the search bar is active, with text in it, and I go to another tab and then back, the controller is black, apart from the actual search bar. Things go back to normal when I cancel and empty the search text field. My question is basically identical to this question: UISearchController causes black screen Swift 2.0

Except that that answer does not solve my problem as you can see. What does solve it is if I change self to searchController, thus: searchController.definesPresentationContext = true. But this results in the search bar appearing in the next controller I tab to. Very confused, please help.

I am using a tableview embedded in a navigation controller and tab bar controller. viewDidDisappear is not being called when the search is active.

Not a solution per se, but a workaround, this stackeroverflow post helped: TableView with SearchController - DEINIT not called . I am not sure if this is some kind of apple bug.

Apparently I am not supposed to use self.definesPresentationContext = true at all. This makes my search appear in all my tabs. But at least viewDidDisappear is called.

In viewDidDisappear, I can hide the search bar with searchController.searchBar.hidden = true and show the bar again in viewDidAppear.

在AppDelegate.swift中

window?.backgroundColor = UIColor.white

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM