views:

8303

answers:

6
+11  A: 

Have you tried:

[viewReceivingKeys resignFirstResponder];

where viewReceivingKeys is the UIView that is receiving the text input?

Frank Krueger
This was excatly what i wanted. Thank you.
Lounges
A: 

use a navigation controller and pop the view when done?

for example, I use code like this to slide an about box in:

[[self navigationController] presentModalViewController:modalViewController animated:YES];

and then when the button in that about box is clicked, I use this to get rid of it:

[self.navigationController dismissModalViewControllerAnimated:YES];

In my case the about box occupies the whole screen, but I don't think it would have to for this to work.

edit: I think I may have misunderstood your question. Something along the lines of my code would be if you are faking the whole keyboard view yourself. I think that resign first responder is the right way to do it if it is the normal keyboard with your toolbar added on top.

frankodwyer
+2  A: 

If your building your own views in Interface Builder, set your view controller to be delegate for the text field and implement textFieldShouldReturn: from UITextFieldDelegate in your views controller.

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField 
{
    NSLog(@"%@ textFieldShouldReturn", [self class]);
    [theTextField resignFirstResponder];
    // do stuff with the text
    NSLog(@"text = %@", [theTextField text]);
    return YES;
}

UITextFieldDelegate textFieldShouldReturn: in the iphone cocoa docs

Ryan Townshend
+9  A: 
Niels Hansen
A: 

I have the same question as Dec, but I want the "go" button to be the "Done" button. Right now, it says "Done" but when I press it it goes down a line. Im new to this, so if your answer is just "Type in the code..." I won't know where to put it. Thanks!

Aidan
If you have a follow up question it's better to post it as a new questionthan as an answer to an old question.In the top right is an "Ask Question" button to do so.You of course can always link to this page for reference in the new question.
sth
Oh, I did. This guy told me to look at this page, and I had a question so.. yeah. But thx.
Aidan
A: 

I read that its not OK to call resignFirstResponder directly: only after a lot of wasted effort did I realize I was looking at the MAC documentation, not the iPhone docs. Its OK on iPhone, not OK on MAC. Grrr.

jamie