The editing a text field, cocoa uses a shared field editor, which switches text fields as the user tabs around the window. This technique is designed to save resources, and it is unlikely it is needed on modern hardware, but for now we're stuck with it.
The field editor brings up a number of issues, here are some helpful tips for handling them.
There is usually a single shared editor for a window, but the window delegate can provide a custom field editor or different editors for different text fields. To return a custom field editor, use the window delegate method windowWillReturnFieldEditor:toObject:
To test whether a text field is being edited, check [field currentEditor], which returns the field editor or nil if the text field is not being edited.
To get from the field editor to the current text field, you use (NSTextField*)[fieldEditor delegate].
The field editor is added as a subview of the text field. So to determine if a text field is the current first responder, use [textField.window.firstResponder isDescendantOf:textField]. Note that you need to check that textField.window.firstResponder isKindOfClass:[NSView class] first.
Posted Friday, May 6, 2011. Permalink. Post a Comment.
None yet.
Comments