UISearchController retain issue

一世执手 提交于 2019-12-01 06:59:40

Hey there I ran into the issue today apparently I need to force the dismiss of the searchController to work around the retain issue

  override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    searchController?.dismissViewControllerAnimated(false, completion: nil)
  }

here is my sample project https://www.dropbox.com/s/zzs0m4n9maxd2u5/TestSearch.zip?dl=0

The solution does seem to be to call dismissViewControllerAnimated on the UISearchController at some point. Most people probably don't do that since the UISearchController is somewhat of an implementation detail related to your view controller that is hosting the UISearchController.

My solution, which seems to work no matter how you present your search UI (standard present or in a popover) is to call searchController.dismissViewControllerAnimated() from your host's viewDidDisappear, after checking to see if the view controller is no longer being presented. This catches all cases, especially the popover case where the user taps outside the popover to automatically dismiss the UI, or the case where the search UI is disappearing simply because you pushed something else onto the navigation stack. In the latter case, you don't want to dismiss the UISearchController.

override func viewDidDisappear(animated: Bool)
{
    super.viewDidDisappear(animated)

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