• 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
Re: NSControl Subclass and First Responder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSControl Subclass and First Responder


  • Subject: Re: NSControl Subclass and First Responder
  • From: "Wood, Tobias C" <email@hidden>
  • Date: Tue, 10 May 2011 10:24:08 +0100
  • Acceptlanguage: en-US, en-GB
  • Thread-topic: NSControl Subclass and First Responder

For posterity, if anyone needs the answer to this, I discovered that I need to also over-ride needsPanelToBecomeKey to return YES so that a mouse-click can give focus to the control. I found this in the ClockControl example, I'd not seen that method before.
Toby

On 5 May 2011, at 23:40, Wood, Tobias C wrote:

> 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

_______________________________________________

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

References: 
 >NSControl Subclass and First Responder (From: "Wood, Tobias C" <email@hidden>)

  • Prev by Date: Re: setState has no effect on an NSButton
  • Next by Date: Why NSClassFromString(@"CADisplayLink")?
  • Previous by thread: NSControl Subclass and First Responder
  • Next by thread: NSTextView and NSTextContainer size & clipping area
  • Index(es):
    • Date
    • Thread