I can't find in the Docs where they explain all those fields and what they mean. Especially "Controller Key" is not clear to me.
views:
562answers:
4It has to do with key-value coding. You can bind a control in IB to a value in your controller. To connect that value, you have to specify the keypath to it. For example, if you have a textfield in IB and you want to bind it to say a field called 'name' in your controller, you would specify 'name' as the keypath. You then need to set up your name field in your controller to be accessible through key-value coding. This is done in 10.5 by using the @property and @synthesize specifiers.
The Controller Key pop-up menu is a way to help you discover what keys the controller (typically a NSArrayController, NSObjectController or a NSTreeController) presents.
The best example is the selection
key of NSArrayControllers, which contains the set of selected objects. What is confusing is the NSObjectController presents a 'selection' key too, although the controller can control only a single object (therefore the selection = the object).
I agree that it is not clear at all. I personnally began to understand it when I bound my objects programmatically (i.e. using the bind:toObject:withKeyPath:options:
method).
Take a look at this topic: http://stackoverflow.com/questions/1774022/cocoa-key-value-bindings-what-are-the-explanations-of-the-various-options-for-co/2440537#2440537
I posted an explanation of where to find definitions for all Controller Key's there.
[Copying my answer on another question…]
The controller key is the key for the (property of the controller object) you're binding to. The model key path is the key path by which the bound object can ask the model objects for more basic objects, such as strings or images, or for other model objects (i.e., drill down into the model).
An example: Let's say you have a Person objects in an array controller, and each Person has a name
. You bind a table column to the array controller, controller key arrangedObjects
(thereby getting the model objects), model key path name
(thereby getting the value objects).
A more complex example: Suppose you have an array controller of Departments. Each Department contains Persons (employees in the department). You can bind your People array controller to the Departments controller, controller key arrangedObjects
(getting the Department model objects), model key path @distinctUnionOfObjects.employees
(getting the Person model objects), and then bind a table column to the People controller, controller key arrangedObjects
, model key path name
.
That table would be for people who work for your company; if you have a separate table of prospective employees, you can create Person objects for them, too, and they won't show up in the table of existing employees because they're not in a Department. When you hire them, you'll add them to one or more Departments; then, they'll show up in the People array controller automatically, because that array controller is observing the employees
of all of the Departments.