textField:shouldChangeCharactersInRange:replacementString vs. UITextFieldTextDidChangeNotification
I'm building a Passcode Lock view, and I want to set the text to a dot on one of the four box labels when a user enters a new charact开发者_StackOverflower into the text field.
Should I use textField:shouldChangeCharactersInRange:replacementString or UITextFieldTextDidChangeNotification?
Using textField:shouldChangeCharactersInRange:replacementString seems easier, but shouldChangeCharactersInRange seems more correct.
I’d recommend using the delegate method, rather than the notification.
Another option: set the text fields’ secureTextEntry
property to YES. (See the documentation for the UITextInputTraits protocol, which UITextField conforms to).
精彩评论