Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide UISearchBar Cancel Button

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 sees it. The problem is that the following code hides the button, but only after displaying it to the user for a millisecond (e.g., it flashes on the simulator and device and then disappears out of view).

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller  {     controller.searchBar.showsCancelButton = NO; } 

Is there a better way to hide it?

like image 815
ArtSabintsev Avatar asked Dec 13 '11 21:12

ArtSabintsev


1 Answers

I managed to hide the "Cancel" button by subclassing UISearchBar and override this method:

-(void)layoutSubviews{     [super layoutSubviews];     [self setShowsCancelButton:NO animated:NO]; } 
like image 159
Nim Gat Avatar answered Sep 22 '22 23:09

Nim Gat