NSView 对象作为 IBOutlet 响应
我陷入了一个我无法解决的问题。 我有一个 CourtView : NSView ,我可以在其中绘图并存储我的 mouseDownPoint 和 mouseUpPoint 。 我有一个 WindowManager : NSObject ,其中有 CourtView 作为 IBOutlet CourtView *courtView;
我想做的是,一旦释放鼠标,那么 - (void)mouseUp:(NSEvent *)event;被调用时,会调用 WindowManager 中的一个方法。
i am stuck on one problem that i am not able to solve.
I have a CourtView : NSView in which i can draw and where it stores my mouseDownPoint and mouseUpPoint.
And I have a WindowManager : NSObject which has CourtView as an IBOutlet CourtView *courtView;
What i want to do is that as soon as the mouse is released, so - (void)mouseUp:(NSEvent *)event; is called, a method in WindowManager is called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为
CourtView
提供对WindowManager
实例的引用,以便它可以在mouseUp
方法中调用它。有多种方法可以做到这一点,但鉴于您已经使用 IBOutlet 来以其他方式链接它们,最简单的方法可能是反向执行相同的操作。将
IBOutlet
实例变量添加到CourtView
的界面:在 Interface Builder 中,您现在应该能够在
CourtView
中的此插座之间添加连接和现有的 WindowManager 对象。然后,在CourtView
的实现中,让您的事件处理程序将相关消息发送给manager
:You need to give
CourtView
a reference to theWindowManager
instance so that it can call through to it in themouseUp
method. There are several ways to do this, but given that you already use anIBOutlet
to link them the other way, probably the simplest is to do the same in reverse.Add an
IBOutlet
instance variable to the interface ofCourtView
:In Interface Builder, you should now be able add a connection between this outlet in your
CourtView
and the existingWindowManager
object. Then, in the implementation forCourtView
, have your event handler send the relevant message tomanager
: