我尝试在此处实施此帖子中发布的第二个答案。我有作为提出问题的人的愿望,但是我mouseDown
没有工作/注册。这就是我所拥有的。
- AppDelegate.h
- AppDelegate.m
- MouseDownTextField.h
- MouseDownTextField.m
并有相关内容:
AppDelegate.h
#import <Cocoa/Cocoa.h> #import "MouseDownTextField.h" @interface AppDelegate : NSObject <MouseDownTextFieldDelegate> { NSWindow *window; IBOutlet NSMenu *statusMenu; NSStatusItem *statusItem; NSMutableArray *selector; NSMutableArray *display; NSTimer *timer; MouseDownTextField *quoteHolder; } @property IBOutlet MouseDownTextField *quoteHolder; @end
AppDelegate.m
- (void)displayString:(NSString *)title { NSRect frame = NSMakeRect(50, 0, 200, 17); quoteHolder = [[MouseDownTextField alloc] initWithFrame:frame]; [[self quoteHolder] setDelegate:self]; [quoteHolder setStringValue:title]; [quoteHolder setTextColor:[NSColor blueColor]]; [test addSubview:quoteHolder]; [statusItem setView:test]; } -(void)mouseDownTextFieldClicked:(MouseDownTextField *)textField { NSLog(@"Clicked");}
MouseDownTextField.h
#import <Appkit/Appkit.h> @class MouseDownTextField; @protocol MouseDownTextFieldDelegate <NSTextFieldDelegate> -(void) mouseDownTextFieldClicked:(MouseDownTextField *)textField; @end @interface MouseDownTextField: NSTextField { } @property(assign) id<MouseDownTextFieldDelegate> delegate; @end
MouseDownTextField.m
#import "MouseDownTextField.h" @implementation MouseDownTextField -(void)mouseDown:(NSEvent *)event { [self.delegate mouseDownTextFieldClicked:self]; } -(void)setDelegate:(id<MouseDownTextFieldDelegate>)delegate { [super setDelegate:delegate]; } -(id)delegate { return [super delegate]; } @end
关于可能是错的或我做错了什么的想法?