First off, thanks very much for the lengthy response. My initial response to your post was rejected for length, so I am trying to abbreviate here, pinpointing areas of confusion.

Hmm. An NSArrayController doesn't manage tables, it manages an array (as its name implies). So, do you have an array somewhere with instances of the Word class? Where is it? For example, is it a property of File's Owner, with a key "words"?
The class structures are:
Word has three ivars {characters, reading, english} (all strings)
WordList has (for now) just one ivar {wordList} (a mutable array)

Word has the appropriate accessors to conform to KVC. That's as far as my certainty goes. Here are the main points of confusion.

1. I'm not sure about WordList. I got an error message about wordList not being KVC compliant. So after reading your response and additional links on KVC compliance for arrays (one-to-many relations, think it was), I suspected I might need to provide WordList with something like....

- (void)insertObject:(Word *)word inWordListAtIndex:(unsigned int)index {
[[self wordList] insertObjectAtIndex: index];
}
- (void)removeObjectFromWordListAtIndex:(unsigned int)index {
[[self wordList] removeObjectAtIndex: index];
}

Unfortunately, that didn't work.

2008-06-05 14:06:20.015 Table Practice[670:10b] An uncaught exception was raised 2008-06-05 14:06:20.016 Table Practice[670:10b] [<AppController 0x13aca0> valueForUndefinedKey:]: this class is not key value coding- compliant for the key wordList. 2008-06-05 14:06:20.016 Table Practice[670:10b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<AppController 0x13aca0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key wordList.'

I recognize here that this error was generated in reference to AppController, not WordList, but it seems crazy to me that I would have to place KVC-compliant code in a controller. So I think something is wrong with the bigger setup. Which brings up issue #2.

2. In my case, File's Owner is simply the proxy for NSApp, and since I can't subclass it, it's not the place for me to add wordList, as you suggested I might. I think you had a Doc-App structure in mind for placing wordList in there, but I haven't really gone into Doc-Apps yet. I'm familiar with using FO as a way to connect window controllers to the nib. But given that I'm using NSApp as File's Owner, one question becomes where or how to tie in my WordList instance and its ivar worList.

This is confusing for two reasons:
a) Someone in the series of File'sOwner posts pointed out that much of the beginner's code drops a part of the model into the nib, but that this is bad coding practice. b) Some bindings examples use an additional homemade controller and some don't. I'm not quite following the reasoning behind this decision.

3. I think one thing is starting to be clear. If you are going to truly separate M from V, then you generally make two sets of bindings.

1. Bind some view object to some controller (presumably the NSController subclass, though I'm not totally sure). 2. Bind some controller (again, presumably the NSController subclass) to some model object.

Maybe this leads to a key concept I'm trying to grapple. When are you binding to values, and when to content? You suggested I look at the reference for NSArrayController with respect to contentArray. They had this to say:

contentArray
an indexed collection that specifies the content of the NSArrayController. The indexed collection is an NSArray instance or subclass, a property that is accessible using the key-value-coding indexed accessor methods, or is accessible through mutableArrayValueForKey:.

But I'm still a little fuzzy here. In my example, wordList is the indexed collection. So I thought that should be it. But you said the object class should be Word because wordList is an array of *Word* objects. I'm obviously missing this key distinction (between value and content), because to me either of the following sentences make sense:

a) I want my array controller to reflect (bind to) the values in the table

b) I want my array controller to reflect (bind to) the contents of the table

(all with the understanding that "reflecting" is a loose term to mean a reciprocal and bidirectional communication so that changes on one side are reflected in the other)

Now, as to the question of what to bind to (arrangedObjects, arrangedObjects.key, selection.key, etc.), that depends on what you're trying to accomplish. If you want to access all of the objects in the array being managed by an array controller, you bind to that controller's "arrangedObjects" controller key.

In my case, I think the answer is yes. I want to display everything in the wordList => use arrangedObjects (?).

If you want to access a particular property of the objects in that array, you specify a model key path to that property.
In my case, the answer is again yes. I want to access specific values of those objects => use the model key path. This will be especially true once I'm ready to add the detail view. Again, this is a point where it seems fuzzy. To me, since my model objects are WordList and Word, my path should be for column 1 should be wordList.word.<ivar1>. But InterfaceBuilder is offering "self" as a starting point. I'm not even sure who "self" is. The NSArrayController or my separate controller containing an instance of WordList?

Typically, custom controllers are different kinds of things from NSController-derived objects. Search the Cocoa Fundamentals Guide for the phrases "mediating controller" and "coordinating controller".
Having at least tried bindings, that distinction is beginning to make more sense now than it did two months ago.

4. My NSArrayController has a "content" outlet that clearly needs to be set. What do I set it to? I could drag it to AppController (which has the WordList instance as an ivar). Or I could drag it directly to the table in the window. To my mind, either could legitimately be deemed "desired content".

As the File's Owner discussion took some 70 emails to resolve itself, I'm trying my best to pinpoint what key concepts and which parts of the documentation and the IB interface are not making sense to me. Maybe that will help hone in on where I've gone astray. Thanks.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to