UISearchController searchBar showsCancelButton not being respected

后端 未结 12 2322
北荒
北荒 2021-02-13 03:58

I\'ve added a UISearchController to my application and set it\'s searchBar to the titleView of my navigationItem.

This works but I am seeing t

12条回答
  •  执念已碎
    2021-02-13 04:05

    I had to correct by putting in a little hack...

    Setting the alpha to 0.0 on viewDidLoad because he screen will flash.

    Before you ask...willPresentSearchController will not work.

    extension GDSearchTableViewController: UISearchControllerDelegate {
        func didPresentSearchController(searchController: UISearchController) {
            searchController.searchBar.setShowsCancelButton(false, animated: false)
            searchController.searchBar.becomeFirstResponder()
            UIView.animateWithDuration(0.1) { () -> Void in
                self.view.alpha = 1.0
                searchController.searchBar.alpha = 1.0
            }
        }
    }
    

提交回复
热议问题