Finding out the NSTextField for a field editor

1.1k views Asked by At

I' using

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

to provide my own field editor so i can display a custom context menu. This works but when inside the "menuForEvent:" method of my field editor, how can i find to which NSTextField it is attached?

EDIT: okay i found that i get it via inside the TextView via

[[[[self window] firstResponder] nextResponder] nextResponder]

The question is - is this a good solution or a hack. I have to skip an internal responder of class _NSKeyboardFocusClipView so i scared that this might not work on future Cocoa versions.

1

There are 1 answers

2
Sven On BEST ANSWER

I wouldn't want to rely on the responder chain for that, seems rather fragile.

I'd try to add a property to my field editor class and set that to anObject in the windowWillReturnFieldEditor:toObject: delegate method.