2

I have an NSTextView, which I want to use as the field editor of an NSTextField.

Since there will be other NSTextFields in the view that do not use a custom field editor, it seems I should use NSCell's method

- (NSTextView *)fieldEditorForView:(NSView *)aControlView

I can't wrap my brain around how to call this, though and have not found any examples of it in use.

NSCell's docs say that 'aControlView' is :

The view containing cells that require a custom field editor.

Which my brain is saying means 'the view this NSTextField is in', and not the NSTextField (as a subclass of NSView).

NSView *viewTheTextFieldIsIn;
CustomTextView *customTextView subclass of NSTextView (the field editor)
NSTextField *textField

However:

[[textField cell] fieldEditorForView:customTextView];

makes no sense to me because its not viewForFieldEditor:...but its on NSCell.

Would someone have mercy on me, and un-snarl my thinking?

lulu
  • 669
  • 10
  • 26
  • a further note: i'm using the fieldEditor to provide text completions. The class does provide this correctly as a text view, but a one-line text view does not resemble NSTextField's look, so I thought using it as a field editor for NSTextField was a better idea. – lulu Dec 05 '10 at 03:00

1 Answers1

-1

Just thought I would answer this for the archive as I think i understand it now, (amazing what sleep will do).

The specific method call's usage can be:

 CustomTextView *customTextView = (CustomTextView *)[[self.textField cell] fieldEditorForView:self.textField];
[customTextView doSomeOtherStuffWithIt];

The customTextView can be used as a fieldEditor by using the window's delegate method:

-(id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client

where client can be the textField.

Then the call to fieldEditorForView on the textField will return that CustomTextView.

lulu
  • 669
  • 10
  • 26
  • As I understand it, you don't call the method yourself. The documentation reads, "This is an override point for NSCell subclasses designed to use their own custom field editors. This message is sent to the selected cell of aControlView using the NSWindow method in fieldEditor:forObject:." –  Apr 18 '11 at 17:16
  • 1
    Also, NSCell's -fieldEditorForView documentation reads, "Returning non-nil from this method indicates skipping the standard field editor querying processes including windowWillReturnFieldEditor:toObject: delegation." In other words, by implementing -fieldEditorForView, the window delegate method isn't even called. –  Apr 18 '11 at 17:56
  • thanks, preston, for clearing up my erroneous answer. what i can do now is use the window's delegate method to check the identity of a field and respond by returning a subclassed `NSTextView` as a different field editor. this seems to be working. – lulu Apr 19 '11 at 22:00