Note that there are some explanatory texts on larger screens.

plurals
  1. POtextShouldEndEditing does not get called in NSTableView
    text
    copied!<p>When a user adds a new managed object, it shows up in a table, which scrolls down to the new entry, and the name of the new object (a default value) goes into editing mode.</p> <p>I need to check if the name of the new object is unique in the datastore, so I can't use a formatter for this. I think the perfect moment where I should validate this, is whenever the user tries to commit the entry's name value, using <code>textShouldEndEditing:</code>.</p> <p>I subclassed <code>NSTableView</code> and overrid following methods, just to be able to check in the log if they get called.</p> <pre><code>- (BOOL)textShouldEndEditing:(NSText *)textObject { NSLog(@"textSHOULDendEditing fired in MyTableView"); return [super textShouldEndEditing:textObject]; } - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor { NSLog(@"control:textShouldEndEditing fired in MyTableView"); return YES; } - (void)textDidEndEditing:(NSNotification *)aNotification { NSLog(@"textDIDEndEditing fired in MyTableView"); } </code></pre> <p><code>textDidEndEditing:</code> gets called fine, but <code>textShouldEndEditing:</code> does not. </p> <p>In the <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html" rel="nofollow">NSTableView Class Reference</a>, under Text Delegate Methods, both methods <code>textShouldEndEditing:</code> and <code>textDidEndEditing:</code> are listed. Someone please explain why one gets called and the other doesn't.</p> <hr> <p>I think the <code>NSTableView</code> acts as the delegate for an <code>NSTextField</code> that gets instantiated as a <em>black box</em> delegate for the <code>NSTextFieldCell</code>. So what is referred to as <em>delegate</em> methods in the <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html" rel="nofollow">NSTableView Class Reference</a>, actually implement the text manipulating methods for the <code>NSTextField</code> object.</p> <p>I tried to declare the <code>NSTextFieldCell</code> as an outlet in my <code>NSTableView</code>. I also tried to declare several protocols in the <code>NSTableView</code>.</p> <pre><code>#import &lt;AppKit/AppKit.h&gt; #import &lt;Cocoa/Cocoa.h&gt; @interface MyTableView : NSTableView &lt;NSTextDelegate, NSTextFieldDelegate, NSControlTextEditingDelegate, NSTableViewDelegate, NSTableViewDataSource&gt; { } @end </code></pre> <p>Don't laugh, I even tried to declare my table view as its own delegate :P</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