i have a custom UIView which is presented from a UIViewController. This view controller can present one of several such views. One of these views has a UITextView. when one begins entering text in the UITextView, the keyboard is shown. however, I want to dismiss the keyboard whenever the user taps anywhere outside the textview. as multiple UIViews can be presented by the UIViewController based on certain condition, I encapsulated the UITextView delegate methods etc in the custom UIView, I did this using Notifications from within the custom UIView like
- (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];
}
however, when the didTapAnywhere is called, the keyboard does not get dismissed even when the resignfirstresponder ties place. FYI, the delegate for the UITextView is the custom UIView.
ple help in how to do this