Re: Detecting focus on control
Re: Detecting focus on control
- Subject: Re: Detecting focus on control
- From: Erik Stainsby <email@hidden>
- Date: Sat, 11 Aug 2012 09:15:59 -0700
On 2012-08-10, at 7:30 PM, Andy Lee <email@hidden> wrote:
> If there's one specific control class that you want to detect focus for, you can subclass it and override becomeFirstResponder. If super returns true, do your thing.
>
> If you want to apply this to a bunch of varied controls, you might want to use a subclass of NSWindow and override makeFirstResponder: (again, checking what super returns).
>
> --Andy
>
So I do have a handful of cases which I will want to swap in editing views for the display views. So I have a subclass of NSWindow with the following method:
- (BOOL) makeFirstResponder:(NSResponder *)responder {
if([super makeFirstResponder:responder]) {
if([responder isEqualTo:[self.windowController displayField]]) {
NSLog(@"%s- [d] %@", __PRETTY_FUNCTION__, __LINE__, @"call activateEditorView");
[self.windowController activateEditorView:self];
}
return YES;
}
return NO;
}
The windowController has the following method:
- (IBAction) activateEditorView: (id)sender {
// self.displayField is the field which triggers this line of action
if([self.displayField resignFirstResponder]) {
NSLog(@"%s- [d] %@", __PRETTY_FUNCTION__, __LINE__, @"replaceSubView:with:");
[[self.window contentView] replaceSubview:self.displayView with:self.editorView];
[editorView setNeedsDisplay:YES];
}
}
Sadly, although the messages are logged the -replaceSubview:with: does not accomplish any change. Have I done (or not done) something foolish in here? I have tried moving firstResponder out of the displayField prior to the replaceSubview: call but without apparent effect on the replaceSubview: outcome (relocating the focus did happen).
~ Erik
_______________________________________________
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