title: How to get contents of a NSTextFieldCell in a cell-based outline when the user quits while editing
body: <p>The previous version of this question was closed because the moderator did not recognize that this is a cell-based Outline not a view-based outline. The answer the moderator suggested does not work for a cell-based outline.</p>
  <p>The question as previously asked was:</p>
  <p>I have a cell-based NSOutlineView. How do I get the contents of the NSTextFieldCell when the user Quits the app while editing that cell. Currently, attributedStringValue returns the contents before editing began.</p>
  <p>As requested in the comments, here is a NSViewController.h and .m .  It references a storyboard with two outlets:  outlineView and cellOutlet as shown in viewController.h.</p>
  <p>ViewController.h</p>
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  
  @interface ViewController : NSViewController &lt;NSOutlineViewDataSource,NSOutlineViewDelegate, NSTextStorageDelegate, NSTextViewDelegate, NSWindowDelegate, NSTextFinderClient,NSTextFieldDelegate,NSSearchFieldDelegate&gt;
  @property (weak) IBOutlet NSOutlineView *outlineView;
  @property (weak) IBOutlet NSTextFieldCell *cellOutlet;
  @property(nonatomic,strong)NSMutableAttributedString* string;
  @end
  </code></pre>
  <p>and ViewController.m</p>
  <pre><code>#import &quot;ViewController.h&quot;
  
  @implementation ViewController
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  }
  
  -(void)viewWillAppear
  {
      self.outlineView.dataSource = self;
      self.outlineView.delegate = self;
      self.outlineView.window.delegate = self;
      self.string = [[NSMutableAttributedString alloc] initWithString:@&quot;TEST&quot;];
  }
  
  - (void)setRepresentedObject:(id)representedObject {
      [super setRepresentedObject:representedObject];
  
  }
  
  -(BOOL)windowShouldClose:(NSWindow *)sender
  {
      [self.view.window makeFirstResponder:nil];
      BOOL response = [sender makeFirstResponder:sender];
      NSMutableAttributedString* changedText = [[_cellOutlet attributedStringValue] mutableCopy];
      NSLog(@&quot;On Quit value was: %@&quot;, changedText);
      return response;
  }
  
  -(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
  {
      NSMutableAttributedString* string = [[NSMutableAttributedString alloc] initWithString:@&quot;Outline Item&quot;];
      return string;
  }
  
  -(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
  {
      return NO;
  }
  
  - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
  {
      {
          return _string;
      }
  }
  
  - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
  {
      if (!item)
      {
          return 1;
      }
      else
      {
          return 0;
      }
  }
  
  - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
  {
      _string = object;
      NSLog(@&quot;Changed Value:  %@&quot;,_string);
  }
  @end
  </code></pre>