Ben Packard
Ben Packard

Reputation: 26476

Bindings - master detail array controllers

I really hope someone can help on this because I'm learning cocoa and have hit a road block.

I am trying to model a simple poker tournament. For now, my entities are simply a Tournament (with a number) and a Player (with a Name). A Tournament has an array of Players.

I can bind two independent table views to display the tournaments and the players just fine. But I want the players table view to just show the players that belong to the selected tournament from the first table view.

Each has it's own array controller. I have tried a variety of different bindings for the second (players) table but to no avail. Has anyone accomplished this? If so maybe you could spell it out for me, as I there are few examples online.

I have the bound the column in the players table view to this second Player AC, controller key arranged objects. But what to put in the Model Key Path? I know it is working because if I stick @count in there I get the correct number of players for the selected tournament. But 'name' and 'player.name' are no good. Is there any kind of 'item.name' or 'players.item.name' I can try?

Sooo close, thanks for the help so far: alt text

Upvotes: 3

Views: 2042

Answers (2)

Ben Packard
Ben Packard

Reputation: 26476

I found the answer here:

Implementing parent->child drill down in Cocoa with Core Data bindings that span multiple entities.

  • The child controller needs to know about the managedObjectContext through its own binding.
  • The child controller must not be in Entity Mode, but rather operate as a NSMutableDictionary class.
  • And, finally, the child controller does not prepare its data. It retrieves it from the parent, through the Content Set binding. Use the controller key selection, and the model key path that connects to the children.

I'm surprised this is not a more commonly used practice, and hope the next person reading this doesn't spend so long finding the answer!

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 816462

I think this tutorial will help you. They also create a master/detail view.

In short: Bind the contentArray of your player's array controller to the tournament's array controller, set ControllerKey to selection and the remaining properties accordingly to your model.

Upvotes: 4

Related Questions