开发者

textField:shouldChangeCharactersInRange:replacementString vs. UITextFieldTextDidChangeNotification

开发者 https://www.devze.com 2023-03-02 15:49 出处:网络
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.

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).

0

精彩评论

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