【问题标题】:How to show keyboard after used inputView如何在使用 inputView 后显示键盘
【发布时间】:2012-07-27 22:21:53
【问题描述】:

我使用inputView 为我的textfield 显示uipickerview,但我对其他功能使用相同的textfield。使用inputViewtextfield 后如何显示标准键盘?

textfield.inputView = pickrView;

【问题讨论】:

  • textfield.inputView = NO;为我工作

标签: ios xcode uitextfield uipickerview inputview


【解决方案1】:

只是

textfield.inputView = nil;

为我工作

【讨论】:

  • 你最好使用 nil 或 NULL 而不是 NO。 inputView 属性需要 UIView 而不是 BOOL。虽然这适用于 NO,因为 nil 并且 NO 都是数字 0,但如果您指定 YES,这将失败并崩溃。
【解决方案2】:

正如Pavel Kaljunen所说,你只需要将inputView设置为nil,但是当键盘已经可见时,你必须先resignFirstResponder,将inputView设置为nil,然后再次成为FirstResponder。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.35];

[yourTextField resignFirstResponder];
yourTextField.inputView = nil;
[yourTextField becomeFirstResponder];

[UIView commitAnimations];

【讨论】:

    【解决方案3】:

    我认为这段代码可能可以工作

     [textField.inputView addTarget:self action:@selector(doTest) forControlEvents:UIControlEventTouchUpInside];
    
    - (void)doTest
    {
      if([textFiled isFirstResponder])
      {
        [textFiled resignFirstResponder];
      }
      else
      {
        [textFiled becomeFirstResponder];
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-20
      • 1970-01-01
      • 2020-05-26
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      • 1970-01-01
      相关资源
      最近更新 更多