Can the keyboard be dismissed by touching outside of the cell in MonoTouch.Dialog? [duplicate]
Asked Answered
O

2

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?

Ovenbird answered 10/4, 2012 at 22:40 Comment(2)
Can you show the "next" button instead ... like when you're filling in a webform in Safari?Bicuspid
I haven't tried it. I didn't know if the next/done button could have different functionality than the Enter key.Ovenbird
O
1

miguel.de.icaza answered this question on a different thread: https://mcmap.net/q/721246/-monotouch-dialog-dismissing-keyboard-by-touching-anywhere-in-dialogviewcontroller.

His solution:

   var tap = new UITapGestureRecognizer ();
   tap.AddTarget (() =>{
       dvc.View.EndEditing (true);
   });
   dvc.View.AddGestureRecognizer (tap);
Ovenbird answered 19/6, 2012 at 16:50 Comment(1)
you must also add dvc.CancelsTouchesInView = false; otherwise this will cancel all your other clicks on the page!Decreasing
S
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.

Salacious answered 17/4, 2012 at 17:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.