self.definesPresentationContext = true: leads to black screen?

大憨熊 提交于 2021-01-28 21:13:01

问题


    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.


回答1:


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.




回答2:


in the AppDelegate.swift

window?.backgroundColor = UIColor.white


来源:https://stackoverflow.com/questions/35943496/self-definespresentationcontext-true-leads-to-black-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!