views:

263

answers:

1

i'm having problems working out how to get a custom nsview to communicate that something has happened to my main controller class.

the controller class has an instance of mapView like this:

IBOutlet MapView *mapView;

which is instantiated through interface builder, and in my mapView class, i'm getting mouse clicks like this:

- (void)mouseDown:(NSEvent *)theEvent { //whatever...

but when this happens, a variable or two needs to be changed in the controller class - how can i do this?

+2  A: 

Define a protocol for your custom View class and implement the protocol in your controller, in your view class youll have a delegate property in your view that implements the protocol code... that property would look like

@property(assign) id <MyProtocol> myProtocolDelegate;

then the Controller can set itself as the delegate for the view and if it implements the protocol correctly should get the messages when invoked by the view. Info here http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html

Daniel