views:

190

answers:

1

Hi there,

I'm having trouble understanding how to get the following working in interface builder.

I've created a Core Data model class "Person" that has a number of attributes (first name, surname, etc.) and a relationship to other persons (friends).

Conceptually this is very simple. However figuring out how to get this working in IB is proving tricky.

I've created an interface that has a table down the left side of the window listing all people. On the right side are the fields for inputting a persons details.

I'd like to have a smaller table that shows the "friends" on the right side together with add and remove buttons. Clicking the add button will launch a small panel with searching functionality for filtering the list down so that you can select one person who will then be added to the "friends" set.

Can anyone give me some suggestions or point me at an example I can see that does something like this?

Thanks in advance, Matt

A: 

Assuming you already have an array controller holding the all the people, make a second array controller whose content array is bound to the first controller's selection.friends. Connect the add and remove buttons to this controller's actions, and bind the friends table's column(s) to its arrangedObjects property.

Peter Hosey
Thanks for your answer! That's help me heaps.Can I achieve everything - I mentioned above - using bindings alone? Or will I need to add some code regardless?
Sway
You will need to add code to run and respond to the Add Friend sheet. I suggest also supporting drag and drop to the friends list, which means more code (a data source). Bindings and the array controllers will handle the rest of it.
Peter Hosey
Ok will follow your recommendations. Thanks again Peter. Matt
Sway
For some reason when my app starts the "friends" are automatically populated with the complete list of people. Any ideas? Also how can I filter all of the "people" in the select a friend panel? Will I need to create a copy of the people for this panel. Would you suggest doing this? Thanks again.
Sway
“For some reason when my app starts the "friends" are automatically populated with the complete list of people.” Then you bound the table column to the wrong array controller. As for filtering, that's a separate question.
Peter Hosey
Still having lots of trouble. Do you know where I can find an example of this? I've looked on Stackoverflow - and the apple - site but can't seem to find anything. Matt
Sway
You should ask new questions with any new problems you're having.
Peter Hosey
Finally figured it out. I needed to have three NSArrayControllers One for the "people", one for the "friends", and one for the "possible friends". Working fine now. Thanks for all of your help Peter. Matt (Still surprises me that Apple doesn't have an example of this).
Sway