MyNSImageView 是 NSImageView 的子类,这里我有:
@interface MyNSImageView : NSImageView
{
}
@end
@implementation MyNSImageView
//- (void) mouseDown: (NSEvent *) theEvent
//{
// do not wish to implement mouseDown event handler from here
//}
@end
在另一个名为 MainView 的类中,我有:
@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");
}
在 MainView 中,当我单击 ImageView1 或 ImageView2 时,我希望使用 mouseDown1 或 mouseDown2 方法来相应地处理事件,而不是 mouseDown 方法。
我已经阅读了有关目标/操作/委托和响应者的内容,但仍然看不到执行此操作的确切语法。