views:

928

answers:

2

I'd like to add a Done button to the iPhone number pad keyboard. There's even a handy space at the bottom left for just such a button.

Previously, I was using a similar trick to those described in Question 584538 and Luzian Scherrer's excellent blog post, but that stopped working in iOS 4. I can do it by creating a custom inputView, but I'd prefer to extend Apple's keyboard instead of writing my own.

Is there a new way to add a view to the standard keyboard? Has someone published an OSS inputView for this? Is there another way?

+2  A: 

The technique described in Luzian Scherrer's blog post does work in iOS 4.0.

My code to add the button to the keyboard was failing because it was being called from the textFieldDidBeginEditing: delegate method, which (in 4.0) is called before the keyboard window's subviews are created. I fixed the problem by calling my code when UIKeyboardWillShowNotification is observed, which happens late enough.

Will Harris
+3  A: 

I got this working. See the code here: http://gist.github.com/454844

There were two issues:

  1. UIKeyboardWillShowNotification is sent before the keyboard view exists, but it you schedule your code to run on the next run loop pass, they do exist. So you don't have to bother with DidShow which is visually less pleasing.

  2. On iOS 4 the UIKeyboard view was elsewhere in the view hierarchy.

Henrik N
u saved me! ...
mshsayem