iOS8 Cannot hide cancel button on search bar in UISearchController

后端 未结 9 639
后悔当初
后悔当初 2021-01-01 12:26

My goal is to prevent the cancel button from appearing in a search bar in a UISearchController. I started with Apple\'s Table Search with UISearchController sample code and

9条回答
  •  南笙
    南笙 (楼主)
    2021-01-01 12:42

    For iOS 8, and UISearchController, use this delegate method from UISearchControllerDelegate:

    func didPresentSearchController(searchController: UISearchController) {
      searchController.searchBar.showsCancelButton = false
    }
    

    Don't forget to set yourself as the delegate: searchController.delegate = self

提交回复
热议问题