Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

becomeFirstResponder does not show keyboard second time (ios 6 + storyboard)

I have a storyboard, which includes navigation between views. Back and forth, and there is also the possibility to jump all the way to the home screen.

Basically, it works like this:

  • View 1 shows a simple menu.
  • View 2 shows input fields and automatically shows the keyboard.
  • View 3 shows a results table. In this view one can go one step back (to view 2) or back to the home screen (view 1).

The keyboard and everything works perfectly the first time, when the user moves from view 1 to view 2. However, when moving either back from view 3 to view 2, or from view 3 and starting all over again, the keyboard does not show.

In the code, I have becomeFirstResponder in the viewDidAppear method. Also, it will resignFirstResponder when loading view 3. Another interesting fact is that when calling the becomeFirstResponder for the second time, it does return NO (while it returns YES the first time). Also, when returning back to this view the textfields are not possible to select, even though they are userInteractionEnabled.

I am really stuck here, so any help is highly appreciated. I have seen several similar questions to this one, but not found a solution:

  • becomeFirstResponder seems to work only 1st time for shake gesture
  • Adding [myUITextField becomeFirstResponder]; does not bring up keyboard
  • keyboard not responding to resignFirstResponder
  • UITextField becomeFirstResponder works only once
like image 716
Jarle Hansen Avatar asked Oct 07 '12 12:10

Jarle Hansen


1 Answers

I was able to track down the problem in my code. Answering this question myself since it might be helpful to others as well.

My issue was that I didn’t really get the order of events correct. I had a button that would move to the next textfield, and if everything was completed it would move to the next screen. This caused the becomeFirstResponder method to be called and not released (resignFirstResponder) when switching to a new screen.

I guess the main advice I can give (at least what finally worked for me), was to just go through all the becomeFirstResponder and make sure it is released before moving to next screen.

like image 174
Jarle Hansen Avatar answered Oct 19 '22 21:10

Jarle Hansen