UISearchController: searchBar and scopeBar overlap on first touch event

前端 未结 3 2124
清酒与你
清酒与你 2021-02-10 09:22

I\'m trying to implement a simple search bar using Apple\'s latest UISearchController. However I can\'t seem to get it to work correctly if I use the search bar

3条回答
  •  余生分开走
    2021-02-10 09:30

    Update for swift 3:

    searchController.searchBar.showsScopeBar = false
    

    Update for swift 4:

    It seems that in swift 4 and ios 11 the search bar got changed. With the method showed above the scope bar will be inside the search bar in some cases.

    if #available(iOS 11.0, *) {
            navigationItem.searchController = searchController
            navigationItem.hidesSearchBarWhenScrolling = false
        } else {
            tableView.tableHeaderView = searchController.searchBar
        }
    

    This fixed it for me. I use the the form shown above if ios 10 is available. If ios 11 is available i change my technic and set the navigation view controller to the search controller. You will notice it looks exactly as on ios 10

提交回复
热议问题