Yes, you only need to reject it for the one that is currently being edited.
To find out which one is being edited, you can check the -(BOOL)isFirstResponder , which will return YES if it is the first responder (the one being edited), or NO if it is not. Once you know which one is the first responder, you can call -(void)resignFirstResponder on this to get rid of the keyboard.
For example, if you have a method called -(void)aMethod that you want to remove from the current view controller, and you have an array of text elements called textArray , you can do a little loop, for example:
-(void)aMethod { for (UITextField *text in self.textArray) { if ([text isFirstResponder]) [text resignFirstResponder]; return; } }
This way you can have a variable number of text fields, and it will still work.
If you have only one or two text fields, and you do not want to create an Array object, you can do (if the fields have the values text1 and text2 :
-(void)aMethod { if ([text1 isFirstResponder]) [text1 resignFirstResponder]; else if([text2 isFirstResponder]) [text2 resignFirstResponder]; }
In addition, to simplify the future, you can create a category method for UIView (which I do) to get the current first responder, if it exists as a subtitle of this view:
@implementation UIView (GetFirstResponder) - (UIView *)getFirstResponder { if ([self isFirstResponder]) return self; else { for (UIView *subview in self.subviews) { UIView *firstResponder = [subview getFirstResponder]; if (firstResponder) return firstResponder; } } return nil; }
You can put this method at the beginning of any file from which you want to call it, or create a separate file for it and import it.
Once you have this method, you can call:
- (void)aMethod { UIView *view = [self.view getFirstResponder]; if (view) [view resignFirstResponder]; }