Skip to content

Instantly share code, notes, and snippets.

@davidortinau
Created January 8, 2011 16:45
Show Gist options
  • Save davidortinau/770977 to your computer and use it in GitHub Desktop.
Save davidortinau/770977 to your computer and use it in GitHub Desktop.
Dismiss the keyboard when the user clicks Search while using UISearchBar
- (void)viewDidLoad {
{
UIView * subView;
NSArray * subViews = [mySearchBar subviews];
// loop through search bar pieces to get to the text field so you can
// set the delegate and then resign first responder on it
for(subView in subViews)
{
if( [subView isKindOfClass:[UITextField class]] )
{
[(UITextField*)subView setDelegate:self];
}
}
}
#pragma mark UITextFieldDelegate delegate method
// this helps dismiss the keyboard when the "return" key is clicked
- (BOOL)textFieldShouldReturn:(UITextField *)txtField
{
[txtField resignFirstResponder];
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment