In order to access -mouseUp and -mouseDown events in a button I have subclassed NSButton and I also want to store a few extra variables within the object:
@interface MoveButton : NSButton{
unsigned char cmd[3];
unsigned char stop[3];
int r;
struct libusb_device_handle *devh;
}
-(void)mouseDown:(NSEvent *)theEvent;
-(void)mouseUp:(NSEvent *)theEvent;
-(void) setcommand:(char*)first:(char*)second:(char*)third (libusb_device_handle*)device_handle;
-(void) setLight: (char*) light;
@end
Within my window controller I have a number of instances of the subclass each connected to an element in Interface Builder through an IBOutlet.
@interface MainWindowController(){
IBOutlet MoveButton * base_cw;
IBOutlet MoveButton * base_ccw;
@end
Within the initWithWindow function each of the buttons are initialised:
base_cw = [[MoveButton alloc] init];
base_ccw = [[MoveButton alloc] init];
[base_cw setcommand:"00" :"00" :"00":devh];
[base_ccw setcommand:"00" :"00" :"00":devh];
In Interface builder I have changed the class property of each button to MoveButton and connected it to the correct IBOutlet. However when a button is actually clicked on the UI errors are thrown up because the instance variables the it is trying to use are empty. Is it that I haven't connected the in-code object properly with the UI element or am I just going about it the wrong way entirely?