views:

364

answers:

2

I want to create my own number pad to appear after user focus the textfield, so I have two question about it? 1.I use "Interface Builder to add a textfield in my view and select the "Number Pad" as the default pad for user to input number, so when I click the textfield, the number pad appear automaticlly, how can I stop it appear the number pad? because I want to show my number pad.

2.If I custom a view with number button inside it, how can I detect the event when I click the textfield? and whether after I detect the event I add a subview to show my custom number pad or not?

thanks

A: 

I have a partial answer but not an ideal one, and I haven't tried this myself. Take a look at the documentation for the UITextFieldDelegate protocol.

You could have your controller set textField.delegate = self, then have it implement textFieldShouldBeginEditing to show your specialized keyboard somehow and then return NO so that it doesn't go into edit mode. When you tell your special keyboard to show itself, pass it a reference to the text field so it knows where to insert characters. The problem is that this probably won't show a cursor and won't let the user move the cursor to insert characters, etc.

So really this a bit ugly, but it may be sufficient. AFAIK there is no good way to do this :(

Nimrod
+2  A: 

If you are creating a custom number pad (I assume this means a view with a grid of buttons), don't bother using a UITextField; there is no easy way to hide the native keyboard and, for all that trouble, there is nothing useful that the text field gives you.

I recommend creating a custom UIControl subclass. You can detect a touch inside the view and show your custom keypad that way. The documentation explains this pretty well.

benzado
I believe he is correct that you won't get anything special for using a UITextField unless there's something else you want to do.
Nimrod