Can I dismiss the iPhone keyboard by touching the background of DialogViewController (MonoTouch.Dialog)? [duplicate]
Asked Answered
P

2

8

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

I'm using DialogViewController from MonoTouch.Dialogs. I'd like to be able to dismiss the keyboard by clicking on the background of the dialog.

I usually employ the technique of filling the view with a large custom button and placing it behind all the other elements. However, I can't make this work in the DialogViewController. I did this in LoadView and it just froze all the other controls.

Is there a relatively straightforward way of achieving what I want?

Paddle answered 11/8, 2010 at 23:59 Comment(0)
H
7

In view controller:

public override void TouchesBegan (NSSet touches, UIEvent evt)
    {
        base.TouchesBegan (touches, evt);

        myField.ResignFirstResponder();
    }

Edit: From what I've read, you can use the TouchesBegan event for the cell subview instead of the table itself. I'm not positive that works. Good luck :)

Haymes answered 12/8, 2010 at 0:9 Comment(3)
+1 for actually having it in .net :)Bowra
+1 as it's a neat approach to the more general problem. However, it doesn't solve my problem with MonoTouch.Dialog. This is descended from UITableViewController, which doesn't seem to receive the TouchesBegan event.Paddle
-1 Doesn't work for MonoTouch.Dialog which is what the original question was asking.Bouldon
S
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);
Sylvie answered 19/6, 2012 at 17:4 Comment(3)
You could help us out by flagging the question as a duplicate, instead of posting a duplicate answer to a duplicate question.Elastic
I have never done that before. I assume it is just the flag link under the question?Sylvie
Yes. Use the "Other" option in the flagging dialog.Elastic

© 2022 - 2024 — McMap. All rights reserved.