setFirstResponder to NSTextField fails 1st time, works next
setFirstResponder to NSTextField fails 1st time, works next
- Subject: setFirstResponder to NSTextField fails 1st time, works next
- From: Moses Hall <email@hidden>
- Date: Wed, 2 Jul 2008 00:20:53 -0400
Hi folks,
Here's a problem I'm having under Tiger, developing an LSUIElement
application (Input Method server -- it's the UI for IPA Palette
[www.blugs.com/IPA]). I have an NSTabView, one of whose panes has a
search field which is an NSTextField subclass (note that the same
problem occurs if I use an NSTextField). I want to make this field
the first responder when the "Search" tab is chosen. Oddly, it does
not become first responder the first time the pane is selected. It
does not become key, and does not accept text (unless clicked on). If
I move to a different tab and come back, then I get the desired
result: the focus ring is there and I can type into the field.
This is happening inside an NSPanel subclass...
@implementation IPAPanel
-(BOOL)canBecomeKeyWindow {return YES;}
-(BOOL)canBecomeMainWindow {return NO;}
-(void)awakeFromNib
{
[self setHidesOnDeactivate:NO];
[self setBecomesKeyOnlyIfNeeded:YES];
}
@end
Here is my tab switch delegate method:
-(void)tabView:(NSTabView*)tv didSelectTabViewItem:(NSTabViewItem*)item
{
NSLog(@"first responder WAS %@", [_window firstResponder]);
if ([[item identifier] isEqual:@"Search"])
{
[_window makeKeyWindow];
[_window makeFirstResponder:_searchText];
}
NSLog(@"first responder: %@", [_window firstResponder]);
}
And here is the log of events:
### Here's a startup call, switching to the previous session's tab
(from user defaults):
2008-07-01 23:41:28.331 IPAServer[1269] first responder WAS
<IPAPanel: 0x392750>
2008-07-01 23:41:28.358 IPAServer[1269] first responder: <IPAPanel:
0x392750>
### Here's the first time I manually go to the search tab:
2008-07-01 23:41:36.969 IPAServer[1269] first responder WAS
<IPASearchField: 0x35f4b0>
2008-07-01 23:41:36.992 IPAServer[1269] first responder:
<IPASearchField: 0x35f4b0>
### No luck, let's try another tab:
2008-07-01 23:41:42.276 IPAServer[1269] first responder WAS <NSView:
0x351c80>
2008-07-01 23:41:42.276 IPAServer[1269] first responder: <NSView:
0x351c80>
### I return to the search tab and...
2008-07-01 23:41:45.017 IPAServer[1269] first responder WAS
<IPAPanel: 0x392750>
2008-07-01 23:41:45.073 IPAServer[1269] first responder: <NSTextView:
0x395200>
Frame = {{2.00, 3.00}, {448.00, 14.00}}, Bounds = {{0.00, 0.00},
{448.00, 14.00}}
Horizontally resizable: YES, Vertically resizable: YES
MinSize = {448.00, 14.00}, MaxSize = {40000.00, 40000.00}
... now the field editor is the first responder, and it's sized to
match my search field. My happiness is palpable but incomplete ;-)
I have a workaround -- in awakeFromNib I can switch to the Search tab
and then to the correct one, then when the user manually switches
it's the second time so it works... sorta. But it's voodoo. I'd
rather understand what is happening. Does anyone have an idea about
what's going on here?
Much appreciated,
-- Brian "Moses" Hall
www.blugs.com
_______________________________________________
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