开发者

Detecting when UITextField text has changed due to shake undo?

I have a UITextFieldDelegate that does a whole bunch of validation on user input to determine whether or not they should be allowed to end editing. In one particular example, it is not valid to leave the field blank.

Right now I'm using textField:shouldChangeCharactersInRange:replacementString: to validate the text input after each edit by the user.

The problem is this: if the user clears the field (with the little 'x' button), the validation code goes into "invalid" mode and prevents the user from navigating away until they have entered valid text. If the user then shakes the phone to get the old text back, 开发者_开发问答shouldChangeCharactersInRange is not called again and the delegate stays in the "invalid" state instead of recognizing that everything is fine again.

Not sure if I'm using it correctly, but it seems like the built-in UITextFieldDelegate machinery is not able to cope with text changes due to undo / redo.

What's the best way to achieve proper validation in this scenario? Do I really need to subclass UITextField in order to implement motionEnded:withEvent:? Seems like the edit-handling stuff in UITextField should really be independent of whether the user actually typed it or it happened due to undo, so would be bummed if I actually had to go that route.


Hook up a method to the UIControlEventEditingChanged event ("Editing Changed" in IB -- not "Value Changed").

This appears to fire whenever/however the text field changes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜