• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CoreData & Relationship binding not sending updates?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData & Relationship binding not sending updates?


  • Subject: CoreData & Relationship binding not sending updates?
  • From: Lee Morgan <email@hidden>
  • Date: Thu, 19 May 2005 03:39:43 -0400

OK, this is kind of complex (or maybe I'm just making it complex) but here goes...
I have a CoreData model which has two entities. The first entity (called "MasterItem") has a to-many relationship (called "subItems") to the other entity (called "SubItem"). The MasterItem also has a to-one relationship (called "currentSubItem") to the SubItem entity. This allows each master item to contain it's own sub items and a selection of the sub item in use.
I have a table view which lists all master items (one per row). In this table view I have a "subItems" pop-up menu column.
Bound like so...

content:
Bind to: MasterItem Array Controller
Controller Key: arrangedObjects
Model Key Path: subItemsArray

contentValues:
Bind to: MasterItem Array Controller
Controller Key: arrangedObjects
Model Key Path: subItemsArray.displayName

selectedObject:
Bind to: MasterItem Array Controller
Controller Key: arrangedObjects
Model Key Path: currentSubItem

NOTE: As a work around to populate the menu I have sub-classed NSManagedObject for my MasterItem entity and provided the subItemsArray accessor - see: Cocoa-dev thread "CoreData and arrays owned by arrays..."

- (NSArray *)subItemsArray { return [self valueForKeyPath:@"subItems.@allObjects"]; }

Each master item and sub item has a "value" attribute of type float. I need to display the difference of the master item's value from the currently selected sub item's value in a table column. Currently I am doing this by adding another accessor to my MasterItem entity called difference.

- (NSNumber *)difference {
    NSNumber *subItemValue = [self valueForKeyPath:@"currentSubItem.value"];
    NSNumber *masterItemValue = [self valueForKeyPath:@"value"];
    NSNumber *difference = [NSNumber numberWithFloat:[subItemValue floatValue] - [masterItemValue floatValue]];
    return (difference);
}

And binding the table column like so...
value:
Bind to: MasterItem Array Controller
Controller Key: arrangedObjects
Model Key Path: difference

This all works out nice and good, expect for one case. When the user changes the currently selected sub item by using the pop-up menu the difference value isn't updated. It only updates when the user chooses the change any other value of either the master or sub item.

I'm thinking I need to add a observer for the currently selected sub item and update the difference value manually when it changes. However I just wanted an opinion or two on if I'm going about this problem in the right way or not?


Thanks,
Lee
 _______________________________________________
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

  • Follow-Ups:
    • Re: CoreData & Relationship binding not sending updates?
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Drag a row and create a file
  • Next by Date: Re: CoreData & Relationship binding not sending updates?
  • Previous by thread: Re: Drag a row and create a file
  • Next by thread: Re: CoreData & Relationship binding not sending updates?
  • Index(es):
    • Date
    • Thread