UItextView disables the keyboard when pressed outside the text field

i has a custom UIView, which is represented from a UIViewController. This view controller may represent one of several such representations. One of these representations has UITextView. when you start typing in UITextView, the keyboard is displayed. However, I want to remove the keyboard whenever the user deletes any point outside the text field. since several UIViewsUIViewController can be represented based on a specific condition, I encapsulated delegation methods UITextView, etc. in custom UIView, I did this using notifications from custom UIViewboth

- (void)configureView
{ 
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

[nc addObserver:self selector:@selector(keyboardWillShow:) name:
 UIKeyboardWillShowNotification object:nil];

[nc addObserver:self selector:@selector(keyboardWillHide:) name:
 UIKeyboardWillHideNotification object:nil];

self.tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                           action:@selector(didTapAnywhere:)];
}

-(void) keyboardWillShow:(NSNotification *) note {
[self addGestureRecognizer:self.tapRecognizer];
}

-(void) keyboardWillHide:(NSNotification *) note
{
[self removeGestureRecognizer:self.tapRecognizer];
}

-(void)didTapAnywhere: (UITapGestureRecognizer*) recognizer {    
[self.detailsTextView resignFirstResponder];
}

, didTapAnywhere, , resignfirstresponder. FYI, UITextView custom UIView.

,

+3
2

Try

[self.view endEditing: YES];

. . , ...

+5

UITextViewDelegate detailsTextView.delegate = self viewDidLoad , TextView.. , ...

+2

All Articles