Re: Core Data/Bindings Issue re: pop-ups and multiple relationships
Re: Core Data/Bindings Issue re: pop-ups and multiple relationships
- Subject: Re: Core Data/Bindings Issue re: pop-ups and multiple relationships
- From: Elise van Looij <email@hidden>
- Date: Tue, 14 Nov 2006 14:29:24 +0100
Op 12-nov-2006, om 18:22 heeft Andrew R. Kinnie het volgende geschreven:
I am trying to create a document-based app small app that uses Core
Data and bindings. I'm having strange data consistency issues with
popup buttons.
I'm experimenting with a Core Data app and Cocoa bindings as well, so
I hope that together we know more than alone.
My app is a helper app for a non-computer game similar to a role-
playing game. I have an entity called "Character" which has a to-
one relationship to another entity called "Nationality" (and vice
versa as a to-many).
The interface has a tabview which has an item for character, an
item for spotting and an item for firing. The Character
tabViewItem is where the user can set up the participants in the
game. There is a table for nationalities, where the user can
create and delete nationalities. There is another table for
characters in the selected nationality. I have an
NSArrayController called Nationalities which is set to that
entity. I have another called Characters which is set to that
entity, but has bindings to the Nationalities array controller's
selection.characters key. This seems to work fine.
I'll assume that means that the contentset of the
Characters_ArrayController is bound to the
Nationalities_ArrayController on selection.characters.
However, when I try to create interfaces for the other
tabViewItems, I seem to be having trouble, especially when I use
popup buttons. I created a popup for the spotter's nationality
bound as follows:
content -> Nationalities - arranged objects
content value -> Nationalities - arranged objects - nationality
name (a string)
selected object -> Characters - selection - nationality
I'll also assume that your data model looks something like this:
Characters
-----------------
name (attribute: string)
nationality (relationship: destination =Nationalities, inverse
=Nationalities.characterers)
Nationalities
-------------------
nationality name (attribute: string)
characters (relationship: destination = Characters, inverse =
Characters.nationality, To-Many)
If you do have it set up like that, then the Content, ContentValues
and SelectedObject of the pop-up button are set correctly, but the
Nationalities_ArrayController must only have the ManagedObjectContext
set, nothing else. So remove the contentset binding. If you need an
arraycontroller for nationalities which is dependent on a selection,
you'll need to create a separate array controller.
The only reason I know this, by the way, is because I alt-dragged one
of my entities to an empty tab on my window in Interface Builder and
when it asked me if I wanted to make an interface for it, I click on
Many Objects. This creates a box with a tables, fields and pop-up
boxes that works perfectly. You can then examine the attributes and
bindings that IB creates to see how you should set up your own controls.
Another issue is: I was under the impression that you only needed
one array controller for each entity, but there seems to be an
issue with this, because, especially in the Spot tabViewItem, I
need the nationality popup for the spotter to filter characters so
I only see the characters of that particular nationality. Then, I
also want to select another character being spotted, so I want
either a table or another couple popups to select the nationality
of the character being spotted, and the characters within that
nationality. So I guess my question is, should I create a
different ArrayController for each differently filtering? In other
words, an array controller for spotters and another for spot targets?
You need *at least* one controller for each entity, but a complex app
could certainly use many more. It's possible, for instance, to filter
your data (say, all nationalities that start with an M or all
characters older than 32 or whatever) with so-called predicates and
then you would set up one controller for each predicate.
Elise van Looij
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden