Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xcode99

macrumors newbie
Original poster
Sep 4, 2008
1
0
I'm new to xcode/cocoa and objective-c programming and was looking for a onMouseHover event for my application. I've looked through the documentation and it doesn't seem to have one.

How do I go about programming this?

I've created a subclass of NSView but don't know where to go from there.

Code:
subClass.h

#import <Cocoa/Cocoa.h>

@interface subClass : NSView
{
}

- (void)mouseMoved:(NSEvent*)theEvent;
@end

Code:
subClass.m

#import "subClass.h"


@implementation subClass

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }
    return self;
}

- (void)mouseMoved:(NSEvent*)theEvent {
	[text setStringValue:@"mouse moved"];
}


@end

Is there a way to add a mouse event using Interface builder just like how an 'action' or 'outlet' can be instantly added?

Also, do all actions execute on a leftmouseclick event? Is there a way to override this?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
What exactly is the problem? If mouseMoved: isn't getting called you probably need to call setAcceptsMouseMovedEvents:YES on the view's window.

I'd suggest looking at the documentation for NSResponder. All views inherit from this.
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
Look at the mouseEntered: & mouseExited: methods (inherited from NSResponder), they should do what you want.

(Note - Mac apps generally don't change state on mouse-over to the same extent Windows & web apps do. Be wary of doing too much on mouse-over.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.