Re: Core Data/Bindings Issue re: pop-ups and multiple
Re: Core Data/Bindings Issue re: pop-ups and multiple
- Subject: Re: Core Data/Bindings Issue re: pop-ups and multiple
- From: Andrew Kinnie <email@hidden>
- Date: Tue, 14 Nov 2006 09:10:27 -0800
On Tuesday, November 14, 2006, at 11:11AM, <email@hidden> wrote:
>Date: Tue, 14 Nov 2006 14:29:24 +0100
>From: Elise van Looij <email@hidden>
>Subject: Re: Core Data/Bindings Issue re: pop-ups and multiple
> relationships
>To: List Cocoa Developer <email@hidden>
>Message-ID: <email@hidden>
>Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
>
>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.
I agree. It seems the docs are good, but the tutorials seem to be too simple and don't clearly indicate what some of the bindings are for, or rather how one would use them practically. It makes it tough to really get a handle on how to do more complex things through practice. Though to me it doesn't seem that I'm doing much that's all that complex.
To synthesize my problem in this case, I guess there are two elements:
1. I want a popup button to list all the nationalities. I want the user to be able to select one and have that selection provide a filter for populating the other character popup. (i.e. the character popup will only display characters from the nationality selected in the first popup)
2. I don't want the nationality selected to change anything in the characters (i.e. selecting a different nationality shouldn't change what characters point to what nationality)
As a related matter to #2, for some reason the nationality popup currently is only populated at all if in one of the other tabs, a nationality is selected which contains characters.
>
>> 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.
Yes, that's the way it is set up.
>
>> 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.
Unfortunately, I tried to do that and create an interface automatically, but no interface appeared for some reason. I got a blue outline of a box inside the Window. I have no idea why. It did create array controllers for me however.
Thanks for giving me this insight though on using other array controllers to act as filters for the main ones. If I understand this correctly, you mean have one Nationality controller, which is set to that entity, but only has the managedObjectContext set. (this is as I have it now) This will return all notionalities, and no user interface element should be bound to it, just other array controllers. Then create other controllers for each popup or table bound to all the nationalities? Or perhaps have one for spotterNationality, one for spotTargetNationality or some such, with character array controllers bound to those via selectedObject?
I'd try this now, but I'm at work and don't have my mac handy.
>
>
>> 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