我可以在模拟器上运行我的应用程序,当我单击文本字段时,键盘将被解除。如果我在设备上运行应用程序并在键盘启动时触摸文本字段外部,则键盘不会被解除。我已经覆盖了TouchesEnded方法,但它没有被调用(UIAlertView仅供我查看方法是否被调用,但从未显示警报)。这是我的代码
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 ();
}
}
关于我做错的任何想法?
**编辑:**通过这样做得到了它。
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 ();
}
}