Question: What's the correct way to resign the current firstResponder? 

I've seen the following:
Looping through fields and calling resignFirstResponder on each.

```
[[self textFieldForRow:0] resignFirstResponder];
[[self textFieldForRow:1] resignFirstResponder];
[[self textFieldForRow:2] resignFirstResponder];
[[self textFieldForRow:3] resignFirstResponder];

```

And this which looks like it's calling a private function, is this app store safe?:

```
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView   *firstResponder = [keyWindow performSelector:@selector(firstResponder)];   
[firstResponder resignFirstResponder];      

```

Is there a better way? 

Thanks!

Comments:
Looks like the second method is using a private api and someone's app has been rejected because of it: [link](https://stackoverflow.com/questions/1823317/how-do-i-legally-get-the-current-first-responder-on-the-screen-on-an-iphone)

Answer: 
There's actually an API to do this:

[view endEditing:YES];

<http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/endEditing>:
The code you have up there is not calling any private function. What is happening is:

```
 //Gets the application window
 UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
 //Gets the first Responder View for the window
UIView   *firstResponder = [keyWindow performSelector:@selector(firstResponder)];  
//Make the UView resign the first responder 
[firstResponder resignFirstResponder];     

```

All of those are public functions, so you will not have any problem with the app store as far as I know. 

Additionally is there a better way to do what exactly?. If you are talking about getting the UIView that is the firstResponder to the keyWindow, you could do when creating your uiview:

```
myView.tag = 100;

```

and to get it:

```
UIView *firstResponder = [self viewWithTag:100];

```