4

How to resignFirstResponder from uiviewcontroller object with is active.

I have five textfields one,two,three,four,five.

   - (void)removeKeyBoard{
     [one resignFirstResponder];
     [two resignFirstResponder];
     [three resignFirstResponder];
     [four resignFirstResponder];
     [five resignFirstResponder];
    }

The above code has done my job, but each object reference to specify for resignFirstResponder.

Is there any way, that handle the resignFirstResponser which ever field is active on UIViewController automatically resign that object.

@All Thanks in advance.

kiran
  • 3,725
  • 5
  • 41
  • 86

2 Answers2

11

Called on whatever view has the textfields in it:

[view endEditing:YES]

UIView reference: Link

Louis Tur
  • 1,223
  • 9
  • 16
  • So its dismissed keyboard appears on screen, with respective any textfield - (void)removeKeyBoard{ [view endEditing:YES]}; – kiran Feb 21 '15 at 07:36
  • If we have have a scroll view on the screen, a view inside scroll view, then we have to keep the reference of inner view to endEditing. – AsifHabib May 30 '19 at 07:03
-2
- (void)textFieldDidEndEditing:(UITextField *)textField {
    [textField resignFirstResponder];
}
Alex Cio
  • 5,752
  • 4
  • 40
  • 73
  • This post has no accompanying text or explanation as to how it answers the question. Would you add an introductory paragraph? Thanks. – halfer Oct 26 '15 at 08:02
  • Further to my earlier feedback, a number of your answers have needed repair (code with no formatting) and all except one are code only, which in general we do not encourage. – halfer Oct 26 '15 at 18:22
  • Your code will allow you to dismiss the keyboard when the user ends editing, but that's not what the OP is asking for. The OP asked how to unconditionally dismiss the keyboard (regardless of which text field is active.) – Duncan C Sep 22 '17 at 13:50