I created a subclass of NSButton in IB and set the subclass as the custom class for my button. The button works, but in my main file ( NSObject ) the " someMethod " which is a IBAction linked to the same button do not work. What i wanted to do is that " if " the subclass ( NSButton ) is clicked, then inside my ( NSObject )the someMethod should exit, as if it was clicked. But i'm lost can't understand why it wont work, please help me out, i'm really lost.
I'm going give you the whole source code, i have the following code in my .h file:
And the following code for the .m file:
This is the main .h file:
and the main .m file
I'm going give you the whole source code, i have the following code in my .h file:
Code:
#import <Cocoa/Cocoa.h>
@interface HoverButton : NSButton
{
NSTrackingArea *trackingArea;
}
- (void)mouseEntered:(NSEvent *)theEvent;
- (void)mouseExited:(NSEvent *)theEvent;
- (void)mouseDown:(NSEvent *)ev;
- (void)mouseUp:(NSEvent *)theEvent;
@end
And the following code for the .m file:
Code:
#import "HoverButton.h"
@implementation HoverButton
- (void)updateTrackingAreas
{
[super updateTrackingAreas];
if (trackingArea)
{
[self removeTrackingArea:trackingArea];
[trackingArea release];
}
NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow;
trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
}
- (void)mouseEntered:(NSEvent *)event
{
[self setImage:[NSImage imageNamed:@"1"]];
}
- (void)mouseExited:(NSEvent *)event
{
[self setImage:[NSImage imageNamed:@"2"]];
}
- (void)mouseDown:(NSEvent *)ev {
[self setImage:[NSImage imageNamed:@"2"]];
}
- (void)mouseUp:(NSEvent *)ev {
[self setImage:[NSImage imageNamed:@"1"]];
}
@end
This is the main .h file:
Code:
#import <Cocoa/Cocoa.h>
@interface Main : NSObject {
}
-(IBAction) someMethod:(id) sender;
@end
and the main .m file
Code:
#import "Main.h"
#import "HoverButton.h"
@implementation Main
-(IBAction) someMethod:(id) sender
{
NSEvent *SKMouseDown; //Mouse down events
HoverButton *frac = [[HoverButton alloc] init];
[frac mouseDown: SKMouseDown];
exit(0); // < --- does not work, someMethod docent work.
}
@end