tags:

views:

41

answers:

2

I have a navigation controller with a controller A having a UITextField.

In another controller view B, I call a public method on the controller A to clear the text on the UITextField.

In controller A, there's a delegate that is implemented:

-(BOOL)textField: (UITextField *)textField 
 shouldChangeCharactersInRange: (NSRange)range 
 replacementString: (NSString *)string

When I'm attempting to clear the UITextField (not in view), I'm unable to trigger the shouldChangeCharactersInRange delegate. Only when UITextField is in view that it works as advertised.

I'm wondering, since it isn't in view when I'm clearing the UITextField that there are implications that I am unaware of? Is this by design?

Basically setting the property of the textfield will not trigger the textfield. Only keyboard entries will.

A: 

I've always been under the impression that programmatically changing UITextField's text property does not trigger -textField:shouldChangeCharactersInRange:replacementString:. If clearing the text in the text field is not enough for you, I think you should execute the appropriate code manually too.

Costique
+1  A: 

From the doc:

The text field calls this method whenever the user types a new character in the text field or deletes an existing character.

not the programmer. So it's by-design.

KennyTM
Ah, missed this. Thanks.
Floetic