Delegate Messages and Notifications
Although you could alter the text view’s behavior by subclassing the text view and overriding
insertText:replacementRange: and doCommandBySelector:, a better solution is to handle the event in the text view’s delegate. The delegate can take control over user changes to text by implementing the textView:shouldChangeTextInRange:replacementString: method.
To handle keystrokes that don’t insert text, the delegate can implement the
Note: To modify editing behavior, your first resort should be to notification or delegation, rather than subclassing. It may be tempting to start by subclassing
NSTextInputContext
Search Fields
textView:doCommandBySelector: method.Note: To modify editing behavior, your first resort should be to notification or delegation, rather than subclassing. It may be tempting to start by subclassing
NSTextView and overriding keyDown:, but that’s usually not appropriate, unless you really need to deal with raw key events before input management or key binding. In most cases it’s more appropriate to work with one of the text view delegate methods or with text view notifications.NSTextInputContext
Search Fields
沒有留言:
張貼留言