Objective-C, how is resignFirstResponder generally?

(my boss says) that I have to implement the "Finish" button on navBar so that the various elements in the view (containing the edit box) reject their keyboard (if they were in focus).

It seems that I should iterate over all the elements and then call resignFirstResponder on each of the unforeseen circumstances, that one of them is in focus? This seems a little dirty (and hard to maintain if, for example, someone else adds more items in the future) - is there a better way to do this?

+5
source share
4 answers

I found him!

Thanks to this

I found that all I need is the following: -

-(void) done {
    [[self.tableView superview] endEditing:YES];
}

// [self.view endEditing: YES];

[] , "eventFilter", UITableViewController , , - - . "DismissableUITableView". [ ]

+12

, .

reset :   [[ ] makeFirstResponder: nil]

0

currentTextField Object,

.h

UITextField *currentTextField;

.m .

.

- (void)textViewDidBeginEditing:(UITextView *)textView
{
   currentTextField = textField;
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
   currentTextField = nil;
}

-(IBAction)buttonTap
{
    if([currentTextField isFirstResponder])
        [currentTextField resignFirstResponder];
}

.

0

I think the best way to handle this is by looking for all the subzones of the main view using a recursive function, see the example below

- (BOOL)findAndResignFirstResponder {
if (self.isFirstResponder) {
    [self resignFirstResponder];
    return YES;
}

    for (UIView *subView in self.subviews) {
        if ([subView findAndResignFirstResponder]) {
            return YES;
        }
    }
    return NO;
}

and also you can put this method in your utilities class and you can use it from tap gestures. All you have to do is simply add to the gesture for viewing.

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(hideEverything)];
[self.tableView addGestureRecognizer:gestureRecognizer];

and you can call the hideEverything method;

- (void) hideKeyboard {
    [self.view findAndResignFirstResponder];
    ...
    ...
}
0
source

All Articles