NSSearchField - detect loss of focus
-
I have an NSSearchField in my toolbar and the results of the search
are displayed in an NSTableView - very similar to the way it works in
OSX 10.4 in the search field in the Apple System Preferences panel.
After searching the user can
(a) select an item from the NSTableView or
(b) click anywhere else on the screen to indicate that they are no
longer interested in the search results.
For case (b) how do I detect when the NSSearchField loses keyboard
focus - so that I can then hide the NSTableView?
Thanks, Keith -
Keith,
> I have an NSSearchField in my toolbar and the results of the search
> are displayed in an NSTableView - very similar to the way it works
> in OSX 10.4 in the search field in the Apple System Preferences panel.
>
> After searching the user can
> (a) select an item from the NSTableView or
> (b) click anywhere else on the screen to indicate that they are no
> longer interested in the search results.
That sounds like some very strange UI -- having a click loose the
search results. But, I'll assume you have a good reason for it :)
>
> For case (b) how do I detect when the NSSearchField loses keyboard
> focus - so that I can then hide the NSTableView?
Take a look at resignFirstResponder. You'll have to subclass
NSSearchField, and you can send your delegate a message in this method.
-corbin
resignFirstResponder
- (BOOL)resignFirstResponder
Notifies the receiver that it’s been asked to relinquish its status
as first responder in its NSWindow. NSResponder’s implementation
returns YES, resigning first responder status. Subclasses can
override this method to update state or perform some action such as
unhighlighting the selection, or to return NO, refusing to relinquish
first responder status.
Use NSWindow’s makeFirstResponder:, not this method, to make an
object the first responder. Never invoke this method directly.
See Also: – becomeFirstResponder, – acceptsFirstResponder _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (<Cocoa-dev...>)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/<cocoa...>
This email sent to <cocoa...> -
On Fri, 6 Jan 2006 23:26:17 +1100, Keith Wilson <kswilson...>
said:
> I have an NSSearchField in my toolbar and the results of the search
> are displayed in an NSTableView - very similar to the way it works in
> OSX 10.4 in the search field in the Apple System Preferences panel.
>
> After searching the user can
> (a) select an item from the NSTableView or
> (b) click anywhere else on the screen to indicate that they are no
> longer interested in the search results.
>
> For case (b) how do I detect when the NSSearchField loses keyboard
> focus - so that I can then hide the NSTableView?
Override resignFirstResponder? Actually I have to admit that, faced with
similar situations, what I generally do is to catch the windowDidUpdate
notification; these are sent whenever anything changes, including change of
focus, so you can check for the firstResponder and react accordingly. m.
--
matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt> -
Many thanks Matt,
I had previously tried overriding resignFirstResponder but it was too
hard and too messy for what I'm doing.
Catching windowDidUpdate works fine.
Keith
On 07/01/2006, at 5:16 AM, Matt Neuburg wrote:
> On Fri, 6 Jan 2006 23:26:17 +1100, Keith Wilson
> <kswilson...>
> said:
>> I have an NSSearchField in my toolbar and the results of the search
>> are displayed in an NSTableView - very similar to the way it works in
>> OSX 10.4 in the search field in the Apple System Preferences panel.
>>
>> After searching the user can
>> (a) select an item from the NSTableView or
>> (b) click anywhere else on the screen to indicate that they are no
>> longer interested in the search results.
>>
>> For case (b) how do I detect when the NSSearchField loses keyboard
>> focus - so that I can then hide the NSTableView?
>
> Override resignFirstResponder? Actually I have to admit that, faced
> with
> similar situations, what I generally do is to catch the
> windowDidUpdate
> notification; these are sent whenever anything changes, including
> change of
> focus, so you can check for the firstResponder and react
> accordingly. m.
>
> --
> matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
> A fool + a tool + an autorelease pool = cool!
> AppleScript: the Definitive Guide
> <http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
>
>
>



