0
votes

Thanks for the help.

Core Data project. I'm importing text from a text file and I want to display it in an NSTextView whose value binding I have bound to the arrayController's selection with model key path text. The array controller contains instances of my entity, which has a string attribute named text. I want to update the arrayController for the key value bound to the textView so it can be saved. No errors when building, but not working. How do I do this?

id newObject = [arrayController newObject];

[arrayController addObject:newObject forKey:@"text"];

[newObject release];
1
“I want to update the arrayController for the key value bound to the textView so it can be saved.” What?Peter Hosey
You need to tell us more about your setup, too. What sort of objects does your array controller contain? What binding of the text view did you bind? What controller key did you use? What model key path did you use?Peter Hosey
Peter, It's a basic data base with a tableView as the source list and a textView. When I type text into the textView, I'm able to save the data in both the source list and textView as well as maintain their relationship to one another. However - If I import text using an open panel, the textView text goes away if I flip through the source list items, and it obviously cannot be saved. Apparently I need to add some code so that the imported text is set just the same as if it was typed in. With me?Paul
Here's the test project. Type in text and save. Then import .txt file and you will see what I'm talking about. s3.amazonaws.com/code-examples/textViewTest.zipPaul
I edited your question to include the answers to the questions I asked.Peter Hosey

1 Answers

0
votes
[arrayController addObject:newObject forKey:@"text"];

This is “not working” because an NSArrayController doesn't respond to such a message. An array controller controls an array, not a key-value mapping; it does not have keys you can add objects for.

That, in turn, is because “array” in Cocoa means an ordered consecutive list, not an associative array. Cocoa calls a key-value mapping/associative array a “dictionary”.

The model key path is exactly that: The key path into the model of the property you want to bind the text view to. You seem to already know this; I assume you entered text here because it's what you named the attribute in your model. Your binding is correct.

But this also means that “text” has nothing to do with the array controller. It is a property of the model entities, not the controller. You need to set that property of the model object—in this case, newObject—not in the controller.