【问题标题】:How to close keyboard when finished typing on iPhone在 iPhone 上完成输入后如何关闭键盘
【发布时间】:2010-08-16 03:48:29
【问题描述】:

我一直在寻找有关 iPhone UITextField 的代码/教程。我遇到了关于如何使用 API 命令的示例代码。然后我以编程方式创建了我的文本字段,现在当我按下完成时我无法关闭键盘。我知道命令是 resignFirstResponder。但是我何时以及如何使用它?

这就是我所做的。

textField = [[UITextField alloc] initWithFrame:CGRectMake(yView, xView, 100, 25)];

textField.borderStyle = UITextBorderStyleRoundedRect;

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

textField.returnKeyType = UIReturnKeyDone;

[textField setText:(@"test")];

[self addSubview:textField];

现在,我将 resignFirstResponder 放在哪里?示例代码通过使用 viewController 来完成。我在一个视图中做了我的。我希望可以在视图上完成。

谢谢。

【问题讨论】:

    标签: iphone


    【解决方案1】:

    向文本字段添加一个委托,并使用委托调用textFieldShouldReturn:

    Here is the apple documentation

    【讨论】:

      猜你喜欢
      • 2016-04-15
      • 1970-01-01
      • 2015-11-24
      • 2012-04-06
      • 2011-12-02
      • 2010-09-28
      • 2011-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多