Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Many-To-Many Relationship Interface in Core Data




On Apr 25, 2007, at 5:49 PM, Frank D. Engel, Jr. wrote:
What I want to do (ideally) is add a new NSTable on the same tab as the one for A, which will list all of the "rows" from B, with checkboxes next to them, such that rows in B related to the selected row from the table for A will be checked, and they will be unchecked otherwise (with the checkboxes clickable to change the relationships).
[...]
Even better, could someone give me at least a sketchy outline with the steps to set this up (or some similarly functional interface)?


The data source for the relationship table for view must, obviously, know what is the currently-selected item (or are the currently- selected items if you want to support that) in table A. Given that, you can implement a data source for the relationship table view:

- (int)numberOfRowsInTableView:(NSTableView *)bTableView
{
    return <number of objects of type B>;
}



- (id)tableView:(NSTableView *)bTableView
objectValueForTableColumn:(NSTableColumn *)bTableColumn
row:(int)rowIndex
{
if ([[bTableColumn identifier] isEqual:<anything except the checkbox column identifier>])
{
return <the value appropriate for the row and column>;
}


if ([[bTableColumn identifier] isEqual:<the checkbox column identifier>])
{
NSMangagedObject *moB = <instance of B at rowIndex>;
NSManagedObject *soA = <selected instance of A>
NSSet *relationshipSet = [soA valueForKey:@"relationshipName"];
BOOL b = [relationshipSet containsObject:moB];
return [NSNumber numberWithBool:b];
}
}



If you want to support a multiple selection in table view A, the implementation will obviously be more sophisticated. You'll have to iterate through the selected objects and determine whether moB is a member of the relationship for each of them. If it is for all, return NSOnState; if it is not for all, return NSOffState; if it is mixed, return NSMixedState (wrapped in an NSNumber in each case).


The implementation of tableView:setObjectValue:forTableColumn:row: follows the same pattern, except if the passed-in object's value is 1 then add moB to the relationship if it is absent, and if the passed-in object's value is 0, then remove moB from the relationship if it is present.

mmalc

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Many-To-Many Relationship Interface in Core Data (From: "Frank D. Engel, Jr." <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.