views:

905

answers:

3

I know I can set showsCancelButton to NO for a UISearchBar ... until you tap the search bar text field, and then the cancel button appears anyway! (At least it does for me.)

Is there a way to show the "X" in a circle within the UISearchBar text field vs. having that separate Cancel button show up adjacent to it? Note that this button only appears for me when search mode is active, and this is regardless of the setting for showsCancelButton.

A: 

if you use interface builder it is ery easy to show.it is there by default.i have used search bar in my app and the searchbartextfield has an "X" to clear the textfield

Rahul Vyas
To clarify my question: I'm asking if there's a way to show the "X" in a circle vs. (that is, _instead_ of) having that separate Cancel button show up next to it. Yes, the "X" in a circle will certainly appear once you start entering text, but the Cancel button will remain, regardless of the setting for showsCancelButton.
Joe D'Andrea
A: 

It might be that the "X" is only intended to clear the search field and not to cancel the search, and so the Cancel button must remain once a search is in play, regardless of showsCancelButton.

Joe D'Andrea
A: 

try this

  • (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { // only show the status bar's cancel button while in edit mode mySearchBar.showsCancelButton = NO;

} - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { mySearchBar.showsCancelButton = NO; }

when using this cancel button will not shown.

Rahul Vyas
Doesn't work for me at all. When I add that in, the Cancel button still shows up as soon as I enter edit mode, even as I trace through the line making the setting.
Joe D'Andrea
but it's working in my app.
Rahul Vyas
from where you added UIsearchbar?
Rahul Vyas
Yup. The minute I go to edit the text in the search bar, the cancel button flies in to the right.Wait a sec. Are you using UISearchBar on its own, or as part of the new-to-3.0 UISearchDisplayController? (I'm using the latter.)
Joe D'Andrea
i still haven't use the new UISearchDisplayController.it's available only in 3.0. i have used UISearchBar because my project was in 2.0 OS.You can try using UISearchBAr instead of UISearchDisplayController.
Rahul Vyas