IPhone - problem with UITextView

This is probably easy to do, but I just can't figure it out - how do I finish editing in textview? How can I make the keyboard disappear? or do I need to click on it to make it disappear?

+6
iphone uitextview keyboard
source share
4 answers

First, (to be honest) a fairly simple question, how does this make me wonder if you tried reading the documentation or searching the Internet.

A search for “Apple UITextView documentation” gives this link for class documentation. Similarly, here is the documentation for UITextViewDelegate.

Searching for a “simple UITextView example” gives you a useful example .

Searching for “UITextView fires the keyboard”, the first hit seems to answer your question exactly . (Although he rejects the keyboard on the return key, which may not be what you want.) (Editing - it seems from your second comment this is exactly what you want.)

PS The people above are correct, if a little bit (understandably). You need to implement a UITextViewDelegate. In this doing, if you want to hide the keyboard with the return key, do shouldChangeTextInRange, find @ "\ n" and release the first responder if you get it. Alternatively, add the “Finish Editing” button to your user interface and change the first responder if the user clicks it.

+10
source share

Very simple:

[myTextField resignFirstResponder]; 

will do the trick.

+2
source share

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

+2
source share
 [yourTextField resignFirstResponder]; 

will cause the keyboard to disappear and complete editing.

0
source share

All Articles