0

I am writing a MonoTouch iOS app. I have read many postings about ResignFirstResponder and I am using that.

My app is a typical table view app. I have done my own custom table cell view. The UITextField controls that cause the numeric keypad to come up in the first place are all on the custom table cell.

Currently I have it so that if you tap on the background of the cell I call ResignFirstResponder on all the text fields. This seems to work, but is not intuitive. I had a new beta tester get it last night and he tapped on one of the text fields and the keypad came up and he was lost as to how to get rid of it. After I told him to just tap the background, he now is fine, but obviously I want a solution that is obvious and doesn't require me to tell everyone how it works.

I read one post about a way to add a DONE button to the keypad, but it looked like a total hack and even broke when 3.2.1 came out and I don't want to have to worry about my app breaking when a new OS comes out.

Suggestions?

user856232
  • 1,073
  • 2
  • 14
  • 40

1 Answers1

1

I would keep the background click->ResignFirstResponder that you have already, but add to it.

Curious, what button do you have set in the bottom right of the keyboard? There are options to show a Done, Search, Go, Next etc. buttons that can be setup to ResignFirstResponder. Pick the button that makes sense in your situation.

You can hook into the bottom right button by setting a callback to UITextField.ShouldReturn and calling ResignFirstResponder. You can just return false (that return value is for allowing line breaks in your UITextField).

Found an example here of hooking up ShouldReturn.

jonathanpeppers
  • 26,115
  • 21
  • 99
  • 182
  • I will give this a try. I didn't know you could set that button. I had read about the ShouldReturn, but didn't realize you could change what the button was for. Currently it is set to be a backspace or delete (call it either). – user856232 Jan 09 '12 at 16:47
  • This is a good answer, but not the complete answer. It works for the alpha keyboard and the numbers and punctuation keyboards. It does NOT work for the Number Pad keyboard. The Number Pad keyboard does not have a place for the Done button. Do you have another idea for it? – user856232 Jan 09 '12 at 22:13
  • Sorry, didn't realize it wasn't on the num pad. There is an InputAccessoryView for attaching your own controls to the top of the keyboard, similar to what safari does. See this post: http://stackoverflow.com/questions/4175212/how-to-add-a-uitoolbar-on-top-of-uikeyboard-using-monotouch – jonathanpeppers Jan 09 '12 at 22:20