简体   繁体   English

NSToolbarItem子类不调用事件

[英]NSToolbarItem Subclass not calling events

I've created a subclass for NSToolbarItem and am trying to catch the -(void)mouseDown:(NSEvent *)theEvent in order to change its state (that's what I added in my subclass as NSToolbarItem doesn't support states out of the box). 我已经为NSToolbarItem创建了一个子类,并试图捕获-(void)mouseDown:(NSEvent *)theEvent来更改其状态(这是我在子类中添加的,因为NSToolbarItem不支持开箱即用的状态)。

Problem is that the event mouseDown: is never called, even though I set my toolbar items' class identities in Interface Builder to the one of my new class. 问题是,即使我在Interface Builder中将工具栏项的类标识设置为我的新类之一,也永远不会调用mouseDown:事件。

Why is this? 为什么是这样? NSToolbarItem is related to NSView , so it should be capable of events no? NSToolbarItem与NSView相关,所以它应该能够发生事件吗?

NSToolbarItem is a subclass of NSObject, not of NSResponder. NSToolbarItem是NSObject的子类,而不是NSResponder的子类。 The event is never called because it is never supposed to handle any. 该事件永远不会被调用,因为它永远不会处理任何事件。 An NSToolbarItem is like a NSDictionary for an NSToolbar, it stores what it needs to draw. NSToolbarItem类似于NSToolbar的NSDictionary,它存储需要绘制的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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