• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSControl Subclass and First Responder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSControl Subclass and First Responder
      • From: "Wood, Tobias C" <email@hidden>
  • Prev by Date: Re: No current point for control point bounds
  • Next by Date: NSTextView and NSTextContainer size & clipping area
  • Previous by thread: Re: No current point for control point bounds
  • Next by thread: Re: NSControl Subclass and First Responder
  • Index(es):
    • Date
    • Thread