I have a custom subclass of NSTableView populated with several custom subclasses of NSTextFieldCell . I would like to be able to modify the edited cell using the arrow keys.
I can do this by creating my own field editor (by subclassing NSTextView ) and returning it from the window delegate as follows:
- (id) windowWillReturnFieldEditor:(NSWindow *) aWindow toObject:(id) anObject { if ([anObject isEqual:myCustomTable]) { if (!myCustomFieldEditor) { myCustomFieldEditor = [[MyNSTextViewSubclass alloc] init]; [myCustomFieldEditor setTable:anObject]; } return myCustomFieldEditor; } else { return nil; } }
In MyNSTextViewSubclass I override the methods moveUp: moveDown: moveLeft: and moveRight: to implement my desired functions, and everything works fine. The only problem is that the field editor no longer behaves like a text field cell editor. For example, when I press the Enter key, it inserts a new line into the text field, and does not finish editing.
How do I create a custom field editor that responds in the same way as the default for NSTextFieldCell (with the exception of the four functions that I override)? Or is there a better way to change the functionality of moveUp: moveDown: moveLeft: and moveRight: :?
EDIT: It looks like the field editor sets the text field as its delegate when it is selected for editing. In this case, it would be useful to simply attach control:textView:doCommandBySelector: to the delegate method, as described here , but when I implement this function either in my NSTextFieldCell subclass or my NSTableView subclass, it is never called. Why not?
source share