Swift - 将动作事件更改为UITextField

时间:2016-02-19 10:59:13

标签: ios swift

当用户按下文本字段时,我尝试更改默认操作。我尝试使用storyboard在Editing Did Begin事件中连接我的操作,如下所示。问题是键盘总是出现,但我希望键盘不会出现。

我无法删除文本字段委托方法,因为我在同一视图中有其他文本字段。

我该怎么办?

screen

3 个答案:

答案 0 :(得分:0)

<强>更新 尝试使用单个文本字段键盘永远不会显示

func textFieldDidBeginEditing(textField: UITextField) {
    if textField == yourTextField
    {
        textField.inputView = UIView()
    }
}

答案 1 :(得分:0)

将您的视图控制器设置为textField委托,并实现UITextField textFieldShouldBeginEditing委托方法。

func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
    if textField == yourTextField {
        // implement custom behaviour
        return false
    }
    return true
}

答案 2 :(得分:0)

简单:

func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
    if(textField == YourtextField){
       return false
      }
    return true
  }

或者:

viewDidLoad()yourTextField.inputView = UIView()

两种方式都有效。使用合适的。