I’ve been searching for answers to this question and while I have done the steps I still cannot seem to get the mouseDown method to be called.
What I want is when the user clicks and holds down on the image, it should print out “Mouse down!”.
(Eventually what I want to do is the user to click and hold on the image to cause a sound to play, and when they let go the sound will stop).
Here’s what I have. My header:
@interface MyNSImageView : NSImageView <NSImageDelegate> {
}
@end
And my class:
@implementation MyNSImageView
- (void)mouseDown:(NSEvent *)event {
if ([[self target] respondsToSelector:[self action]]) {
[NSApp sendAction:[self action] to:[self target] from:self];
}
NSLog(@"Mouse Down!");
}
@end
Does this look right? If so, then are there other problems which might be interfering with it? Of not, what should I do?
Thanks heaps!
First thought: Try implementing
acceptsFirstResponderand return yes. Then have your delegate set the first responder to the image view….UPDATE:
So, I just created a new project, and added a class MyClass to it, which inherits from NSImageView. mouseDown is implemented:
and initWithFrame is implemented:
To make the view visible.
I then edited the nib file by adding a custom class to the window, and changing the class of the custom class to MyClass. It worked fine, so I dunno whats wrong.