Created
December 31, 2013 18:49
-
-
Save eralston/8200795 to your computer and use it in GitHub Desktop.
A delegate for resigning a UITextField when the return key is pressed. It's a corrected version of the code here: http://stackoverflow.com/questions/3186065/uitextfield-resign-first-responder-ios4
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
@interface ResignOnReturnDelegate : NSObject <UITextFieldDelegate> | |
@end | |
@implementation ResignOnReturnDelegate | |
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | |
{ | |
if ([string isEqualToString:@"\n"]) { | |
[textField resignFirstResponder]; | |
// Return FALSE so that the final '\n' character doesn't get added | |
return NO; | |
} | |
// For any other character return TRUE so that the text gets added to the view | |
return YES; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment