找出字段编辑器的 NSTextField

发布于 2024-09-15 20:38:32 字数 435 浏览 9 评论 0原文

我用来

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻身的咸鱼 2024-09-22 20:38:32

我不想依赖响应者链,这看起来相当脆弱。

我尝试向字段编辑器类添加一个属性,并将其设置为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文