2

This is probably a very newbie question but I cant find the solution yet.

So I have a simple project with UITextField and once I touch it, the keyboard shows up and I can't hide it any more.

My expectations are that this is default behavior for a text control. Obviously I'm wrong and I need your help guys to find out where.

If you want to reproduce it do the following:

  1. Create new project
  2. Drop a text box in iPhone storyboard
  3. Drop UIButton and attach it to touchUp that will set the text in the text box to "Hello World"
  4. Run in iPhone simulator
  5. Touch the button or directly touch the text box.

Try to close the keyboard ....

Nik Todorov
  • 718
  • 1
  • 5
  • 17
  • I don't think that this is duplicate. If I knew to ask the question from your link or to search for it I would not of asked this question. I'm sorry for my ignorance but thank you guys for your help to overcome it. And yes I have searched a lot before asking, just obviously I need more knowledge to find my answer in the others questions. Anyway thank you for the link, though! :) – Nik Todorov Sep 01 '13 at 03:34
  • How is it not a duplicate? You asked how to dismiss the keyboard when the Return key is pressed. Right? The other question asks the same thing. And the accept answer to that question answers your question. Therefore it is a duplicate. Correct? – rmaddy Sep 01 '13 at 03:37
  • As I mention it I'm total newby with this and my question is "Why is not hiding after touching Done". For you it may be more than obvious that Done is Return for me it is not. Also I did not knew that I need to code something to hide the keyboard My expectation was that hiding should be default behaviour with no need of code for it ... Anyway I see your point too .. I will need a little bit more experience with XCode and I will have better questions :) or find my answers ... anyway I have no intention just to argue. I found my answer. Thanks again! – Nik Todorov Sep 01 '13 at 03:58

1 Answers1

8

You have to implement the delegate method:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
      return [textField resignFirstResponder];
   }
Abdullah Shafique
  • 6,780
  • 7
  • 30
  • 68