Re: Setting focus to text field in drawer
Re: Setting focus to text field in drawer
- Subject: Re: Setting focus to text field in drawer
- From: Arthur Clemens <email@hidden>
- Date: Mon, 11 Aug 2003 10:18:58 +0200
On zondag, augustus 10, 2003, at 06:33 PM, Arthur Clemens wrote:
>
I searched the archives and docs, but cannot find an answer to my
>
problem:
>
>
I have a main window with a NSTextView, and an attached NSDrawer with a
>
search text field in it.
>
From the text view, I want to set focus to the search field using a
>
keyboard shortcut.
>
>
My search text field does become first responder, but no focus ring is
>
drawn and typing does not work; the field editor apparently does not
>
become first responder. The text view in the main window fires a
>
resignFirstResponder:.
>
>
It all works if I click into the search text field, but I cannot make
>
it work programmatically. Obviously I am missing something.
>
I found the source of the problem, though I still don't know exactly
why this happens.
The setup of my program is this:
the text field in the drawer is a subclass of NSTextField, and I also
have subclassed its field editor, in order to mimic Apple's search box
functionality in Mail.app and Safari (magnifier icon, default gray text
"Search", clicking on it removes default gray text and makes text color
black). So I had overridden becomeFirstResponder in both the text field
as the field editor.
In SearchTextField.m:
- (BOOL)becomeFirstResponder
{
if ( [[[self cell] textColor] isEqualTo:[NSColor grayColor]] ) {
// Save current record first
[self sendAction:@selector(saveChangesToRecord) to:[self
target]];
[self sendAction:@selector(updateUI) to:[self target]];
[[self cell] setTitle:@""];
[[self cell] setTextColor:[NSColor blackColor]];
[self setNeedsDisplay:YES];
}
return YES;
}
I found out that by removing the overridden becomeFirstResponder in the
text field, publiclook's suggestion of
[[_searchField window] makeKeyAndOrderFront:nil];
[[_searchField window] makeFirstResponder:_searchField];
does work. I removed the function calls from becomeFirstResponder of
the text field to the becomeFirstResponder of the field editor.
So it all functions now as it should. But I don't know if I should have
written the text field's becomeFirstResponder differently, or that I
shouldn't have overridden text field's becomeFirstResponder.
Arthur Clemens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.