What does “Controller Key” mean in Interface Builder > Inspector > Bindings?

后端 未结 4 1777
温柔的废话
温柔的废话 2021-01-03 00:33

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.

4条回答
  •  隐瞒了意图╮
    2021-01-03 00:57

    [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.

提交回复
热议问题