This question already has an answer here:
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?
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 whenUIKeyboardWillShowNotification
is observed, which happens late enough.I have submitted this to Apple as a bug. Interface Builder allows the developer to specify a Return Key type for a keyboard type of Number Pad. Bug number 8759674.
Apple followed up by saying that this issue has been previously logged as Bug ID# 5885964 and they closed 8759674.
You can add
inputAccessoryView
with 'Apply' and 'Cancel' buttons, and dismiss the number pad with then.I got this working. See the code here: http://gist.github.com/454844
There were two issues:
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 withDidShow
which is visually less pleasing.On iOS 4 the
UIKeyboard
view was elsewhere in the view hierarchy.I've created a version to enable the horizontal version of the numpad... plug into the technique described in Luzian Scherrer's blog and add the two extra pngs (not included here), and the "isLandscape" boolean into "didRotateFromInterfaceOrientation" method..
I refactored the code and put it on github.
https://github.com/dazuiba/dz-numberpad-done-helper