开发者

NSView Object respond as an IBOutlet

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.


You need to give CourtView a reference to the WindowManager instance so that it can call through to it in the mouseUp method. There are several ways to do this, but given that you already use an IBOutlet to link them the other way, probably the simplest is to do the same in reverse.

Add an IBOutlet instance variable to the interface of CourtView:

@class WindowManager;
@interface CourtView : NSView
{
    IBOutlet WindowManager* manager;

    // ... rest of your interface ...
}

In Interface Builder, you should now be able add a connection between this outlet in your CourtView and the existing WindowManager object. Then, in the implementation for CourtView, have your event handler send the relevant message to manager:

- (void) mouseUp:(NSEvent*) event
{
    // ...

    [manager someWindowManagerMethodWithEvent:event andOtherArgument:whatever];

    // ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜