0

Possible Duplicate:
MonoTouch.Dialog: Dismissing keyboard by touching anywhere in DialogViewController

I noticed that when touching outside of the table cell (which I suppose is the 'section'), the touchesBegan method does not get called so I can't call EndEditing or ResignFirstReponder.

I am creating a multiline entry element; because of this, the return key goes to a new line instead of "returning". This is the intended behavior. However, I have no way to dismiss the keyboard then.

I noticed in the settings for menu on the iPhone (General->Keyboard->Shortcuts) or when entering credentials, that touching in the outer area does not resign the responder. Does this mean that this is a limitation of iOS as a whole (or Apple just didn't see fit in these instances)?

Is there anyway to do this?

There is, what I gather, an identical question here but no one came up with a valid answer:
Can I dismiss the iPhone keyboard by touching the background of DialogViewController (MonoTouch.Dialog)?

Maybe in a year and a half someone has solved it?

Community
  • 1
  • 1
valdetero
  • 4,624
  • 1
  • 31
  • 46
  • Can you show the "next" button instead ... like when you're filling in a webform in Safari? – xanadont Apr 11 '12 at 00:43
  • I haven't tried it. I didn't know if the next/done button could have different functionality than the Enter key. – valdetero Apr 11 '12 at 14:49

2 Answers2

1

miguel.de.icaza answered this question on a different thread: https://stackoverflow.com/a/10864640/1134836.

His solution:

   var tap = new UITapGestureRecognizer ();
   tap.AddTarget (() =>{
       dvc.View.EndEditing (true);
   });
   dvc.View.AddGestureRecognizer (tap);
Community
  • 1
  • 1
valdetero
  • 4,624
  • 1
  • 31
  • 46
  • 3
    you must also add dvc.CancelsTouchesInView = false; otherwise this will cancel all your other clicks on the page! – benpage Sep 10 '12 at 06:32
0

I think you have 2 options:

  • Put a "Done" button somewhere
  • Hook up the touch event on the background of your view to dismiss

I think the first option is better, since it is what Safari does.

You can attach a toolbar to the top of the keyboard to simulate what Safari does with InputAccessoryView. Here is an example of doing this in Obj-C (should be easy to port): http://gabriel-tips.blogspot.com/2011/05/input-accessory-view-how-to-add-extra.html

It may not work for your layout, however, if screen real estate is tight. Go with option #2 in that case.

jonathanpeppers
  • 26,115
  • 21
  • 99
  • 182