navigationBar中的UISearchController

Pet*_*Pik 13 ios swift uisearchcontroller

我正在尝试在tableViewController中使用新的UISearchController.

但是当我像使用旧的searchDisplayController一样按下searchBar时,我对它如何在navigationController中向上移动有点困惑?

目前它只是停留在表头.

这是我的代码:

    self.teamSearchController = ({
        let controller = UISearchController(searchResultsController: nil)

        controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
       controller.searchBar.showsScopeBar = true
        self.tableView.tableHeaderView = controller.searchBar

        return controller
    })()
Run Code Online (Sandbox Code Playgroud)

控制器:

在此输入图像描述

当我点击搜索栏时:

在此输入图像描述

Pra*_*I V 20

您可以将UISearchBarUISearchController导航栏,而不是表头

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;

// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;

self.definesPresentationContext = YES;
Run Code Online (Sandbox Code Playgroud)