Created
January 8, 2011 16:45
-
-
Save davidortinau/770977 to your computer and use it in GitHub Desktop.
Dismiss the keyboard when the user clicks Search while using UISearchBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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