• 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: Detecting a focus change in a window?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting a focus change in a window?


  • Subject: Re: Detecting a focus change in a window?
  • From: "Bruce Johnson" <email@hidden>
  • Date: Sun, 24 Sep 2006 17:11:39 -0700

Here is what I did to get the cell that the user clicks or tabs into:

I subclassed NSMatrix and overrode "resignFirstRepsonder" so that it
sent a notification when it obtained the focus

in the .h file
extern NSString * myMatrixAcceptingFocus;

@interface myMatrix : NSMatrix
{
	NSNotificationCenter *matrixCenter;
}

@end

int the .m file
NSString * myMatrixAcceptingFocus = @"myMatrix accepting focus";

@implementation myMatrix
//================================
- (BOOL) acceptsFirstResponder
{
	return YES;
}
//================================
- (BOOL) resignFirstResponder
{
	matrixCenter = [NSNotificationCenter defaultCenter];

	[matrixCenter postNotificationName: myMatrixAcceptingFocus
								object: self];
	return YES;
}
//================================
- (BOOL) becomeFirstResponder
{
	return YES;
}
//================================
@end

Then in my controller class I simply listen for these notifications.
If you want the NSTextfieldCell that was clicked or tabbed into:

in the controller class: (the one listening to the notifications)
- (void) getMatrixNotifications: (NSNotification *) notification
{
	NSLog(@"selected cell = %i", [[[notification object] selectedCell] tag]);
}



----
Bruce Johnson
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Detecting a focus change in a window? (From: Mark Dawson <email@hidden>)
 >Re: Detecting a focus change in a window? (From: Nick Zitzmann <email@hidden>)
 >Re: Detecting a focus change in a window? (From: "Bruce Johnson" <email@hidden>)
 >Re: Detecting a focus change in a window? (From: "email@hidden" <email@hidden>)
 >Re: Re: Detecting a focus change in a window? (From: "Bruce Johnson" <email@hidden>)

  • Prev by Date: Re: Custom view background texture/color
  • Next by Date: Re: Synching CGContextFlush with a Monitor's Refresh Rate
  • Previous by thread: Re: Re: Detecting a focus change in a window?
  • Next by thread: Re: Detecting a focus change in a window?
  • Index(es):
    • Date
    • Thread