简体   繁体   中英

Finding out the NSTextField for a field editor

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM