UITextField delegate methods are not fired when setting text programmatically

ios, objective-c, uitextfield, uitextfielddelegate

Solution

Set the text of UITextField by calling insertText:

aTextField.insertText(" ")

Problem

I've created a custom input view for entering text into `UITextField`. Basically it's just custom designed number pad. I have textfields, on which I've set the inputView property to use my custom created `UIView` subclass. In that view I have collection of buttons - from 0-9 and also backspace. Now I want to change the text of UITextField programmatically when those buttons are tapped. The `UITextField` adopts `UITextInput` protocol, which in it's turn adopts `UIKeyInput` protocol. In that protocol I have all the methods I need, i.e. inserting text into cursor position and deleting text. The problem is that those methods do not fire `UITextField` delegate methods. That is if I have custom validation in `textField:shouldChangeCharactersInRange:replacementString:` field for instance, that won't work. I've tried to set the text property of `UITextField` directly, but that didn't work also. What is the right way of inserting text into `UITextField`, I mean insert text in a way that all delegate methods would be called?

Original source

Related problems