One way to end editing by clicking outside of the textView is not completely trivial. Selecting other text or text fields or activating a navigation control will cause ...
- (void)textViewDidEndEditing:(UITextView *)textView
... on any object that you specified as a textView delegate. You can call it yourself by calling ...
- (BOOL)endEditing:(BOOL)force
... in the view that contains your text box.
Suppose I have a UITextView inside a UITableViewCell (inside a UITable). I want the editing to end by clicking on the table. I could do this:
- (void)viewDidLoad { [super viewDidLoad]; UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapTable)]; [[self tableView] addGestureRecognizer:tapRecognizer]; [tapRecognizer release]; } - (void)didTapTable { [[self tableView] endEditing:YES]; }
Now, when I click on my desk, I am finishing editing. And, as others have said, in textViewDidEndEditing I must definitely call [textView resignFirstResponder];
Ben flynn
source share