开发者

UITextField issue

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开发者_StackOverflow社区 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜