Archive for October 11th, 2009

11
Oct

Snippet: UIKeyboard buttons

So if you’ve done any complicated-ish UI work on the iPhone, you’ve probably thought to yourself “Wouldn’t it be neat if we could add some auxiliary buttons to the keyboard?” And you have doubtless thought that to yourself if you’ve ever used a UITextView allowing return characters to be entered … as there actually is no integral way to dismiss it then! Something like, oh this for instance:

UIKeyboardDismiss.png

Well, here is one way to go about doing so. And a pretty simple way, at that.

Now, having had some spats with Apple over the use of undocumented views ourselves, we’re just a teensy bit leery of the official acceptability of this method, which is to watch for the system notification a keyboard is coming up, then hunt through all the views looking for it …

// Check to see if the description of the view we have referenced is UIKeyboard.
// If so then we found the keyboard view that we were looking for.
if ([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)

… but hey, it works! So although you might want to have a ready Plan B just on the off chance Apple ever decides that UIKeyboard views are Completely Access Verboten™ like they did to us with UIImagePickerView, in the meantime this is a simple way to work around a mildly dysfunctional UI situation, indeed.