Hide UISearchBar Cancel Button

后端 未结 11 884
夕颜
夕颜 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:13

    After UISearchDisplayController deprecated in iOS8, Apple give handle search presentation to UISearchControllerDelegate.

    so you can override searchBar to hide the Cancel button, like below :

    - (void)didPresentSearchController:(UISearchController *)searchController {
        [searchController.searchBar setShowsCancelButton:NO];
    }
    

    if you need hidden Cancel button from inactive state, you need set searchBar on init :

    search = [[UISearchController alloc] initWithSearchResultsController:nil];
    [search.searchBar setShowsCancelButton:NO];
    

提交回复
热议问题