I have a UIButton
and a UITextField
,when the button is pressed the textfield's content string will be equal to: This is a test string
, how can I detect that this text field has changed its contents in this case?
p.s. UITextField's
delegate methods do not work in such case
UPDATE: I want this behavior to be on iOS 6+ devices.
Maybe simple key-value observing will work?
Edit: I just checked it, and it works for me.
You can add the
UITextFieldTextDidChangeNotification
:textField
(param object) is your UITextField.selector
is your method that will be called when this notification was fired.Here is a Swift3 version of akashivskyy's answer:
The delegate method may actually work for you. You get the text field, the range that will change, and the new string. You can put these together to determine the proposed string.
You can handle text change within
UIControlEventEditingChanged
event. So when you change text programmaticaly just send this event:Did u try this?