Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With the understanding that I mentioned in my other post, I figured out an answer. It's a little convoluted but it works. You have to subclass both the NSTextField and the NSWindow because you need information from both to set this up. Here's the subclasses: HMTextField.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface HMTextField : NSTextField { } @end </code></pre> <p>HMTextField.m</p> <pre><code>#import "HMTextField.h" #import "HMWindow.h" @implementation HMTextField - (BOOL)becomeFirstResponder { [(HMWindow*)[self window] setTfBecameFirstResponder:YES]; return [super becomeFirstResponder]; } @end </code></pre> <p>HMWindow.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface HMWindow : NSWindow { BOOL tfIsFirstResponder, tfBecameFirstResponder; } @property (nonatomic, readwrite, assign) BOOL tfBecameFirstResponder; @end </code></pre> <p>HMWindow.m</p> <pre><code>#import "HMWindow.h" @implementation HMWindow @synthesize tfBecameFirstResponder; -(id)init { if (self = [super init]) { tfIsFirstResponder = NO; } return self; } - (NSResponder *)firstResponder { id fr = [super firstResponder]; if ([fr isEqualTo:[self fieldEditor:NO forObject:nil]]) { tfIsFirstResponder = YES; } else { if (tfIsFirstResponder &amp;&amp; tfBecameFirstResponder) { NSLog(@"the text field stopped being first responder"); tfBecameFirstResponder = NO; } tfIsFirstResponder = NO; } return fr; } @end </code></pre> <p>Make the classes and make your objects their class. You'll be notified of the first responder change from your text field where the NSLog message is in the HMWindow.m file. If you need help understanding how it works let me know.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload