【问题标题】:Example of UITextField ResignFirstResponder with Monotouch带有 Monotouch 的 UITextField ResignFirstResponder 示例
【发布时间】:2010-03-16 11:31:15
【问题描述】:

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

【问题讨论】:

    标签: iphone uitextfield xamarin.ios uiresponder


    【解决方案1】:

    这里是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
    }
    

    【讨论】:

    • 大哥!我觉得很n00by :) 再次感谢克里斯!
    • @kentakhy 很高兴能提供帮助,我花了大约 3 个小时才从网上的小片段和 Miguel 的例子中弄清楚:github.com/migueldeicaza/monotouch-samples
    猜你喜欢
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多