views:

46

answers:

1

I'm building a Core Data application, and I want a button to add the selected object (Player) to a relationship (Team) corresponding with that button. Add, fetch, insert? Is this a bindings issue, with Argument and Target?

Thanks a ton in advance for your help, -Dan

+3  A: 

Have an array controller bound to the relationship, and hook up the button to the array controller's add: action. You don't need Bindings for the latter step; that Binding is for setting a button's target dynamically, which is not what you need here.

Peter Hosey
Sorry, I asked too simply:I have the full roster in one table view, and I'd like the "add to team" button to add a player selected from that tableView into a relationship with that team view. While I made the button "add:" for the array controller, I don't think the controller knows where to get the relationship, because so far it still does nothing.
DanF
DanF: I believe you'll want the Argument binding, then. Bind it to the roster controller's `selectedObject` (not `selection`, which is different).
Peter Hosey
I think we're very close! I binded the argument to the roster, and the target to the team, and now when I press it a row is filled on the team (implying SOMETHING is being sent to it!) but there's an error in the console, complaining that I have a null selector. Any guesses what type of selector I should be applying here?
DanF
I'm pretty sure this is the time to subclass the team entity to accept a player as argument to a new method, which I will use as the selector. I'll try it in the morning, but I'm optimistic!
DanF
You don't need to subclass anything, and you don't want the button sending this message to model objects anyway. Bind the Target binding to the array controller, controller key `self`, with selector `addObject:` (note: *not* `add:` this time).
Peter Hosey
It's very strange, most things seem to work now, but when I add a player to a team, it does not display their name, but an open parenthesis, and if I edit it, it edits the name, but reverts to an open parenthesis. When I add a player, I get the error:addObserver:forKeyPath:options:context:] is not supported. Key path: nameWhich sounds like everything is working except the table's relationship to the name, which boggles my mind in its own way. I'll be fiddling with this a bit, thanks for all your help- I love Adium and Growl!!
DanF
I'm an idiot!!! The whole problem was I had the Team Array Controller set to be an Entity of the Team type, instead of the Player type, which is the type of entity it is actually managing! Thanks for all your help!
DanF
I also figured out how to implement the reverse, the trick was that I had to bind the team's tableView both by Value AND by managedObjectContext. That took about the whole day!
DanF