找出字段编辑器的 NSTextField
我用来
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
提供自己的字段编辑器,以便我可以显示自定义上下文菜单。 这是可行的,但是当在我的字段编辑器的“menuForEvent:”方法中时,我如何找到它附加到哪个 NSTextField ?
编辑:好吧,我发现我通过 TextView 内部得到它
[[[[self window] firstResponder] nextResponder] nextResponder]
问题是 - 这是一个好的解决方案还是一个黑客。 我必须跳过 _NSKeyboardFocusClipView 类的内部响应程序,所以我担心这可能不适用于未来的 Cocoa 版本。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不想依赖响应者链,这看起来相当脆弱。
我尝试向字段编辑器类添加一个属性,并将其设置为
windowWillReturnFieldEditor:toObject:
委托方法中的 anObject。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.