Re: Detecting a focus change in a window?
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