Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4618938
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:21:26+00:00 2026-05-22T02:21:26+00:00

MyNSImageView is a subclass of NSImageView, here I have: @interface MyNSImageView : NSImageView {

  • 0

MyNSImageView is a subclass of NSImageView, here I have:

@interface MyNSImageView : NSImageView 
{
}
@end

@implementation MyNSImageView

//- (void) mouseDown: (NSEvent *) theEvent 
//{
//  do not wish to implement mouseDown event handler from here
//}
@end

In another class called MainView, I have:

@interface MainView : NSView 
{
    MyNSImageView *ImageView1;
    MyNSImageView *ImageView2;

}
@end

- (void)awakeFromNib
{
    ImageView1 = [[[MyNSImageView alloc] initWithFrame:NSMakeRect(5, 5, 240, 240)] autorelease];
    NSImage* image1 = [[[NSImage alloc] initWithContentsOfFile: @"/Volumes/MAC DAT2/pictures/MP6107.jpg"] autorelease];
    [ImageView1 setImage:image1];
    [self addSubview:ImageView1];

    ImageView2 = [[[MyNSImageView alloc] initWithFrame:NSMakeRect(300, 5, 240, 240)] autorelease];
    image1 = [[[NSImage alloc] initWithContentsOfFile: @"/Volumes/MAC DAT2/pictures/MP5784.jpg"] autorelease];
    [ImageView2 setImage:image1];
    [self addSubview:ImageView2];
}

- (void) mouseDown2: (NSEvent *) theEvent 
{
    NSLog(@"mousedown2 from MainView");
}
- (void) mouseDown1: (NSEvent *) theEvent 
{
    NSLog(@"mousedown1 from MainView");
}
@end

- (void) mouseDown: (NSEvent *) theEvent 
{
    NSLog(@"mousedown from MainView");
}

In the MainView, when I click on the ImageView1 or ImageView2, I would like to have the mouseDown1 or mouseDown2 method to handle the event accordingly not the mouseDown method.

I have read about target/action/delegate and responder stuff, but still could not see the exact syntax to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:21:26+00:00Added an answer on May 22, 2026 at 2:21 am

    One way to handle this is with a delegate:

    First you declare a delegate protocol for your NSImageView subclass:

    @class MyNSImageView;
    @protocol MyNSImageViewDelegate <NSObject>
    
    - (void)myImageView:(MyNSImageView *)view mouseDown:(NSEvent *)event;
    
    @end
    
    
    @interface MyNSImageView : NSImageView {
    
    }
    // declare the delegate member
    @property (assign) id<MyNSImageViewDelegate> delegate;
    @end
    
    @implementation MyNSImageView
    @synthesize delegate = _delegate;
    
    // In your mouseDown method, notify the delegate
    - (void)mouseDown:(NSEvent *)event {
        if([self.delegate respondsToSelector:@selector(myImageView:mouseDown:)]) {
            [self.delegate myImageView:self mouseDown:event];
        }
    }
    
    @end
    

    Then, declare your MainView class to implement the MyNSImageViewDelegate protocol:

    @interface MainView : NSView <MyNSImageViewDelegate> {
        MyNSImageView *imageView1;
        MyNSImageView *imageView2;
    }
    @end
    

    And in your MainView implementation:

    - (void)awakeFromNib {
        // create your image views then add our instance as the delegate to each
        ImageView1.delegate = self;
        ImageView2.delegate = self;
    }
    
    // here we implement the `MyNSImageViewDelegate` method, which will get 
    // called when any `MyImageNSView` instance we've added ourselves as
    // delegate to gets clicked.
    - (void)myImageView:(MyNSImageView *)view mouseDown:(NSEvent *)event {
        if (view == imageView1) {
            NSLog(@"imageView1 clicked");    
        } else if (view == imageView2) {
            NSLog(@"imageView2 clicked");    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

@interface: UIImageView *myImageView; @property (nonatomic, retain) UIImageView *myImageView; @implementation: @synthesize myImageView; - (void)viewDidLoad {
I have a UIViewcontoroller subclass and the following code is in my viewdidload ,
I have a subclass of UIImageView and would like to pass self as a
So say in my viewcontroller's .h file I have: @interface MyViewController : UIViewController {
I have an UIImageView with an image. Now I have a completely new image
I created UIImageView with the help of Interface Bulder. Now I want to place
i have a imageView in table cell now i want to chnage image on
I have an array of 1000images. I need to sometimes animate till a certain
I'd like to catch event of image changing in my NSImageView, how can I
So i have the below method declaration and definition, -(UIImageView *)returnImageView:(UIImageView *)myImageView color:(UIColor *)imageViewColor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.