ViewWillDisappear not getting called searchcontroller

后端 未结 3 940
一向
一向 2021-02-15 09:40

When I\'m in the middle of a search and then switch UItabs, ViewWillDisappear does not get called. Any idea as to why ViewWillDisappear does not get called when I have filtere

相关标签:
3条回答
  • 2021-02-15 10:05

    I think its the problem with the xcode . Try to close it and reopen the project once again and try to run again

    0 讨论(0)
  • 2021-02-15 10:10

    Similar to @user5130344 I found that subclassing resolved my issue, although I found that isActive = false cleared the search bar where I wanted the search query to remain on returning to the view.

    Here's my subclass instead - this fixed my issue with iOS 13 dismissing the parent view:

    class MySearchController: UISearchController {
    
        override func viewWillDisappear(_ animated: Bool) {
            // to avoid black screen when switching tabs while searching
            self.dismiss(animated: true)
        }
    }
    
    0 讨论(0)
  • 2021-02-15 10:13

    Had the same issue. viewWillDisappear is not called on the UITableViewController, but it is called in the UISearchController.

    So I subclassed UISearchController and overrode the viewWillDisappear method. In my case I just needed to deactivate the search controller.

    class SearchController: UISearchController {
    
        override func viewWillDisappear(_ animated: Bool) {        
            // to avoid black screen when switching tabs while searching
            isActive = false
        }
    }
    
    0 讨论(0)
提交回复
热议问题