Hide UISearchBar Cancel Button

后端 未结 11 866
夕颜
夕颜 2020-12-24 06:39

I have a UISearchDisplayController and UISearchBar hooked up to my ViewController via Outlets from my nib.

I\'d like to hide the cancel button so that the user never

11条回答
  •  甜味超标
    2020-12-24 07:07

    If you want to avoid the subclassing, implement

    searchController.searchBar.showsCancelButton = false;
    

    in these two delegate methods (Do not forget to assign delegates):

    - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
    
    - (void)didPresentSearchController:(UISearchController *)searchController
    

    The first one is called everytime you update the searchBar (Cancel button is visible by default) and the second one is for the first searchBar activation.

提交回复
热议问题