Obj-C:为什么我的NSTextField子类对我没有分配给它的对象有影响? [英] Obj-C: Why is my NSTextField subclass having an effect on objects I haven't assigned to it?

查看:146
本文介绍了Obj-C:为什么我的NSTextField子类对我没有分配给它的对象有影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSPanel,其上有4个不同的NSTextField。我正在寻找通常的剪切,复制,粘贴,选择所有工作的一些字段。

I have an NSPanel with about 4 different NSTextField's on it. I'm looking at getting the usual cut, copy, paste, selectAll working for some of the fields.

我发现的最佳解决方案似乎是这里:
http:// web。 archive.org/web/20100126000339/http://www.cocoarocket.com/articles/copypaste.html

The best solution I've found appears to be here: http://web.archive.org/web/20100126000339/http://www.cocoarocket.com/articles/copypaste.html

AXCVHandler >成为 NSTextField 的子类。在我的NSPanel在接口构建器如果我改变单个NSTextField的类为AXCVHandler,如上面的链接所示,那么我期望的行为将是,只有那个单个文本字段将允许剪切,复制和粘贴。剩下的3个字段不会,因为他们仍然被分配NSTextField类。

The AXCVHandler becomes a subclass of NSTextField. On my NSPanel in interface builder if I change a single NSTextField's class to be AXCVHandler, as shown in the link above, then the expected behavior to me would be that only that single text field would allow for cut, copy, and paste. The 3 remaining fields would not since they are still assigned the NSTextField class.

我看到的是我的预期行为的相反。我为AXCVHandler设置了一个单独的NSTextField,并且突然,我的NSPanel上的每一个NSTextField都在使用剪切,复制,粘贴?!

What I'm seeing though is the opposite of my expected behavior. I set a single NSTextField to the AXCVHandler and all of a sudden every single NSTextField on my NSPanel is working with cut, copy, paste ?!

为什么?剩下的3个文本字段被分配给NSTextField类,但是它们在我的子类中调用了performKeyEquivalent?!

Why is this? The 3 remaining text fields are assigned the NSTextField class yet they are calling performKeyEquivalent in my subclass ?!

我缺少什么?

推荐答案

从您链接到的文章:


这个解决方案的一个有趣的事情是,处理程序对象不需要是动作的目标视图。你可以让一个单独的NSButton执行复制和粘贴操作为整个窗口,如果你想。 (这与单个菜单项可以为您的整个应用程序执行复制或粘贴操作的方式类似。)

One interesting thing about this solution is that the handler object does not need to be the target view for actions. You could make a single NSButton perform the copy and paste operations for your whole window, if you'd like. (This is similar to the way that a single menu item can perform copy or paste operations for your whole application.)

一个想要处理一个键等效的视图不关心哪个视图是第一响应者。它搜索整个视图层次结构。一旦找到单个 AXCVHandler ,该对象将执行键等效操作。它执行的方式是向响应者链发送相应的动作,响应者链从第一响应者开始。因此,一个 AXCVHandler 对象足以将适当的操作指向任何文本字段,因为它们中的任何一个都可以是第一个响应者。

The search for a view which wants to handle a key equivalent does not care which view is first responder. It searches the entire view hierarchy. Once it finds the single AXCVHandler, that object performs the key equivalent. The way it performs it is to send a corresponding action to the responder chain, which does begin at the first responder. So, that one AXCVHandler object is sufficient to direct the appropriate action to any of your text fields because any of them can be the first responder.

这篇关于Obj-C:为什么我的NSTextField子类对我没有分配给它的对象有影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆