gsg822
gsg822

Reputation: 11

Xamarin keyboard dismissing on simulator, but not on device

I'm able to run my app on the simulator and when I click out of the text field, the keyboard is dismissed. If I run the application on my device and touch outside of the text field when the keyboard is up, the keyboard is not dismissed. I have overridden the TouchesEnded method, but it is not getting called (UIAlertView is only there for me to see if method is getting called, but never shows an alert). Here is my code

public override void TouchesEnded (NSSet touches, UIEvent evt)
{
    base.TouchesEnded (touches, evt);
    usernameTxtField.ResignFirstResponder ();
    UIAlertView view = new UIAlertView ("Test", "TouchesEnded", null, "OK", null);
    view.Show ();
    foreach (var item in this) {
        var txtField = item as UITextField;
        if (txtField != null && txtField.IsFirstResponder)
            txtField.ResignFirstResponder ();
    }
}

Any ideas on what I am doing wrong?

**EDIT: ** Got it working by doing this.

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

        foreach(var item in this)
        {
            var txtField = item as UITextField;
            if(txtField != null)
                if (txtField.IsFirstResponder)
                    txtField.ResignFirstResponder ();
        }
    }

Upvotes: 0

Views: 340

Answers (0)

Related Questions