Skip navigation.
 
mlCoreData NSTextView changes: not noticed with KVO, not accessible from program, but stored anyway
FROM : Theo Vosse
DATE : Wed Apr 02 19:12:02 2008

Hi,

I have an NSTextField that has a "data" binding to an 
NSObjectController, configured for an Entity, in a CoreData app 
(freshly created in XCode under Tiger).

When I edit the text field and save the file, all changes are stored. 
But when I try to get the contents in my program, I only get the 
first object read. Changes made after that are simply not visible, 
nor are they passed on to observeValueForKeypath.

The code looks like this:

In the NSDocument derived class:

   IBOutlet NSObjectController* grammarController;

which is connected to an object controller in the nib file, 
configured for the entity GrammarTextObject, which has only one 
interesting member, text, of the type NSData. There is also an 
NSTextField in the nib which has data bound to the object 
controller's selection.text;

Then I try:

       GrammarTextObject* grammarObject = [grammarController 
selection]; // also tried: content
       NSData* grammarText = [grammarObject valueForKey:@"text"];
       NSAttributedString* attrText = [[[NSAttributedString alloc] 
initWithRTF:grammarText documentAttributes:nil] autorelease];

but all I get is the text read from the file, not the text that is 
visible in the text field. Also, attempts to get a notification upon 
change don't work:

   [[grammarController selection] addObserver:self forKeyPath:@"text" 
options:0 context:0]

Does anyone have a clue? Thanks in advance,

   Theo Vosse

Related mailsAuthorDate
No related mails found.