输入键盘键时 UITextField 不更新

UITextField not updating when entering the keyboard keys

当我点击下面屏幕上提到的这个 UITextField 时,会出现数字键盘,问题是当我开始点击数字时,我的 UITextField 没有更新,没有数字, 只有 placeholder.

我需要做什么?

谢谢

正在添加代码!

@IBOutlet weak var salarioTextField: UITextField!

override func viewDidLoad()

{
    super.viewDidLoad()

    updateView()

    salarioTextField.delegate = self
}

func textFieldShouldBeginEditing(textField: UITextField) -> Bool

{

    if textField == feriasTextField
    {
        feriasTextField.inputView = feriasPicker
    }

    else if textField == salarioTextField
    {
        salarioTextField.keyboardType = UIKeyboardType.NumberPad
    }

    else if textField == inicioTextField
    {
        textField.inputView = datePicker
        textField.inputAccessoryView = toolbar
        datePicker.date = inicioDate
    }
    else if textField == motivoTextField
    {
        motivoTextField.inputView = motivoPicker
    }
    else
    {
        textField.inputView = datePicker
        textField.inputAccessoryView = toolbar
        datePicker.date = fimDate
    }
    return true
}

func textFieldDidBeginEditing(textField: UITextField)
{
    backgroundScrollView.scrollEnabled = true
    let scrollSize = CGSizeMake(view.frame.width, view.frame.height)
    backgroundScrollView.contentSize = scrollSize
    activeTextField = textField
    activeTextField?.becomeFirstResponder()
}

func textFieldDidEndEditing(textField: UITextField)
{
    backgroundScrollView.contentSize = CGSizeMake(0, 800)
    backgroundScrollView.scrollEnabled = true
}

请忽略其他UITextField

确保您已为该字段启用用户交互。

如果实现了委托方法textViewDidBeginEditing,可以在这里打个断点或者print语句,看是否触发。

你可以试试在场上叫becomeFirstResponder

我刚刚弄明白发生了什么。

我正在向下面的方法返回 false。

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
    return true;

}

只需将其更改为 true 即可。 感谢您的帮助。