I use the UISearchBar (but not the SearchDisplayController, which is usually used in combination), and I would like to remove the keyboard when you press the "X" button.
I followed TomSwift 's suggestion for a call when "X" is tapped, and this works fine. But the resignation of the first responder from the text field, as well as the call to the UISearchBar instance, as with resignFirstResponder , will not force the keyboard to leave.
Is there a way to get rid of the keyboard when the user presses the X button?
Here is what I did to get the βClearβ message:
- (void)viewDidLoad: { for (UIView* v in searchBar.subviews) { if ( [v isKindOfClass: [UITextField class]] ) { UITextField *tf = (UITextField *)v; tf.delegate = self; break; } } }
Then I have my class setup to implement both UISearchBarDelegate and UITextFieldDelegate.
Having a class as a text field delegate allows me to get this call:
- (BOOL)textFieldShouldClear:(UITextField *)textField { [textField resignFirstResponder]; [self.searchBar resignFirstResponder]; return YES; }
I tried everything I could think of. The last thing I am trying to find is a way to output "searchBarCancelButtonClicked", which UISearchDelegate will call in my Controller class, but not sure how I could do this, since UISearchBar does not seem to have direct methods for being called with this name.
iphone uitextfield uisearchbar
Justin Galzic Nov 16 '10 at 1:37 2010-11-16 01:37
source share