Remove clear button (grey x) to the right of UISearchBar when cancel button tapped

Posted by David Foster on Stack Overflow See other posts from Stack Overflow or by David Foster
Published on 2010-06-16T10:14:15Z Indexed on 2010/06/16 10:33 UTC
Read the original article Hit count: 432

Right, to begin my question, here's some screenies of the problem already solved by the Spotify app:

Spotify's Step 1: Standard UISearchBar not in editing mode.

Step 1

Spotify's Step 2: UISearchBar now in editing mode. Search term entered. Cancel button slides in from the right, and the clear button (grey x) appears.

Step 2

Spotify's Step 3: Cancel button pressed; keyboard slides out and the search bar is no longer in editing mode. Search term remains and the grey x button is now hidden.

Step 3

At present, the following code fires off when my cancel button is pressed:

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    [searchBar resignFirstResponder];
    [searchBar setShowsCancelButton:NO animated:YES];
}

Which results in:

My Step 3: Search bar now not in editing mode. Cancel button and keyboard has slid out. Search term remains but so does the grey x.

Problem

So, my question is this: given that -resignFirstResponder (and -endEditing:, FYI) does not hide the grey x button when a search bar has had text entered into it, how does one hide it?

Thanks again, friends.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c