Note that there are some explanatory texts on larger screens.

plurals
  1. POtextShouldEndEditing does not get called in NSTableView
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COIs it not the `<NSTextDelegate>` protocol that needs to be implemented? Does anyone know how `NSTextDelegate` methods of the `NSTextFieldCell` are forwarded? Is there any documentation around? (Believe me, I've looked) Or is there an object up the command chain that functions by default as `NSTextDelegate` (such as the `NSTableView`)? Is it possible that some `NSTextDelegate` methods are overridden by another class which is first in the command chain?
      singulars
    2. COFound an interesting document in the Mac OS X Developer Libraries: [Cocoa Text Architecture Guide](http://developer.apple.com/library/mac/#documentation/TextFonts/Conceptual/CocoaTextArchitecture/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009459-CH1-SW1), with lots of pointers to other technologies and examples. I'll get back when I know more :)
      singulars
    3. COThe [Text Editing](http://developer.apple.com/library/mac/#documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextEditing/TextEditing.html#//apple_ref/doc/uid/TP40009459-CH3-SW1) chapter of the Cocoa Text Architecture Guide says: **Text Change Notifications and Delegate Messages** _The textShouldBeginEditing: and textDidBeginEditing: messages are sent only once during an editing session. More precisely, they’re sent upon the first user input since the NSTextView became the first responder._ The fact that the text was selected did not notify the text field that editing was being done.
      singulars
 

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