NSControl Subclass and First Responder
NSControl Subclass and First Responder
- Subject: NSControl Subclass and First Responder
- From: "Wood, Tobias C" <email@hidden>
- Date: Thu, 05 May 2011 23:40:49 +0100
- Acceptlanguage: en-US, en-GB
- Thread-topic: NSControl Subclass and First Responder
Hello,
I am trying to create a simple NSControl sub-class that will respond to mouse clicks and key presses, however I cannot get it to take First Responder status despite having over-ridden acceptsFirstResponder to return YES. If I place breakpoints in acceptsFirstResponder and becomeFirstResponder then acceptsFirstResponder is called, returns YES, but becomeFirstResponder never gets called and so the class never receives a keyDown message. Mouse-down messages are received correctly. My current implementation is below, am I missing something simple?
Thanks in advance,
Toby Wood
@implementation testControl
+ (Class)cellClass
{ return [NSActionCell class]; }
- (BOOL)acceptsFirstResponder
{ return YES; }
- (BOOL)becomeFirstResponder
{
[super becomeFirstResponder];
NSLog(@"Became first responder.");
return YES;
}
- (void)drawRect:(NSRect)dirtyRect {
// Drawing code here.
NSRect bounds = [self bounds];
[[NSColor whiteColor] set];
[NSBezierPath fillRect:bounds];
}
- (void)keyDown:(NSEvent *)theEvent
{ NSLog(@"Got a key."); }
- (void)mouseDown:(NSEvent *)theEvent
{
NSLog(@"Got a mouse down.");
[NSApp sendAction:[self action] to:[self target] from:self];
}
@end_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden