Is there an (App Store Safe) way to resign the first responder?

What is the correct way to cancel the current first interrogator?

I saw the following: Scrolling through fields and calling resignFirstResponder for each.

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

And what is like calling a private function, is this application storage safe ?:

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

Is there a better way?

Thank!

Comments: It seems that the second method uses a private api, and because of this, the application-application was rejected: link

+3
source share
4 answers
+3

, , . :

 //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];     

, , .

, , ?. , UIView Responder keyWindow, uiview:

myView.tag = 100;

:

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

, firstResponder , . - :

- (id)my_FirstResponder
    for view in [self subviews]
        if [self isFirstResponder]
            return self
        return [self my_firstResponder]
    return nil

Using a performSelector:method that is not included in the public headers is certainly a reason for refusing, so do not do this. Oh, and don't forget to use a prefix (like the code above) when adding a category to avoid conflicts.

0
source

Source: https://habr.com/ru/post/1730121/


All Articles