iphone - 使用 Monotouch 的 UITextField ResignFirstResponder 示例

标签 iphone uitextfield xamarin.ios uiresponder

我是新手。当用户在 UITextField 中输入文本后,我不知道如何以及在哪里调用 ResignFirstResponder 来摆脱键盘。我对 UIResponder 类有点困惑。 Mono 文档说:“要关闭键盘,请将 UIResponder.ResignFirstResponder 消息发送到当前第一响应者的文本字段。”怎么办呢?有人可以发布一个简单的工作示例吗? Obj-C 中有很多示例,但 C# 中没有。非常感谢。

最佳答案

这是an example I've done recently :

private UITextField _textField;

public override void ViewDidLoad()
{
    _textField = new UITextField();
    _textField.Text = "King Alfonso III";
    _textField.Bounds = bounds;
    _textField.Placeholder = "Username";
    _textField.ShouldReturn = delegate
    {
        _textField.ResignFirstResponder();
        return true;
    };
    View.AddSubview(_textField);
}

此外,如果您提交带有按钮的表单,请确保放弃按钮单击中的所有文本字段,以避免出现响应者错误。

public void ButtonClick(object sender, EventArgs e)
{
    _textField.ResignFirstResponder();
    // All other textboxes

    // Other button logic
}

关于iphone - 使用 Monotouch 的 UITextField ResignFirstResponder 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2453905/

相关文章:

ios - 如何在 iOS 版 MonoTouch/Xamarin 中导航命名空间?

c# - Xamarin.iOS:CAGradientLayer 的圆角边缘模糊

iphone - 点击 UIWebView 中的文本框时键盘不出现

iphone - 如何通过点击更改 UILabel 的 alpha?

iphone - 如何更改 UIActionSheet View ?

iphone - 如何捕获 iPhone 上的所有程序中止错误?

iPhone如何在打字时获取UITextField的文本?

ios - 如何在 iOS 中创建自动完成 [实时] 文本字段,它会在您键入时提供建议

ios - iOS 应用程序中自定义数字键盘的问题

css - MonoTouch Pixate UITableViewCell 样式设置