键入

时间:2017-12-19 13:34:03

标签: ios swift uisearchcontroller

iOS 11搜索栏在输入时一直在消失我试图设置searchController.hidesNavigationBarDuringPresentation = false searchController.definesPresentationContext = true这里是一个正在发生的事情的视频

Video

我的委托功能

func updateSearchResults(for searchController: UISearchController) {
    filarr = arr.filter({ (arr:String) -> Bool in
        if arr.contains(searchController.searchBar.text!){
            return true
        }else{
            return false
        }

    })
    resultController.tableView.reloadData()
}

//Assigning the searchbarcontroller
if #available(iOS 11.0, *) {
        self.navigationController?.navigationBar.prefersLargeTitles = true
        self.navigationItem.searchController = searchController
        self.navigationItem.hidesSearchBarWhenScrolling = false
    } else {
        tableView.tableHeaderView = searchController.searchBar
    }

2 个答案:

答案 0 :(得分:5)

您需要在显示dependencies { compile files('libs/jackson-annotations-2.9.0.jar') compile files('libs/jackson-databind-2.9.0.jar') compile files('libs/jackson-core-2.9.0.jar') compile 'com.google.android.gms:play-services:11.0.4' compile 'com.android.support:appcompat-v7:25.2.0' } apply plugin: 'com.google.gms.google-services' 的视图控制器上将definesPresentationContext设置为true

你这样做:

searchController

但应该这样做:

searchController.definesPresentationContext = true

答案 1 :(得分:0)

您需要添加 viewDidLoad()

searchController.hidesNavigationBarDuringPresentation = false