• 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
Re: Many-To-Many Relationship Interface in Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Many-To-Many Relationship Interface in Core Data
  • From: "Frank D. Engel, Jr." <email@hidden>
  • Date: Thu, 26 Apr 2007 20:09:22 -0400

I am trying to implement this solution, but ran into a bit of a problem I'm not quite sure what to do with.

I got this to compile cleanly.


In my run log, I am seeing this (quite repeatedly):

[NSEntityDescription entity]: selector not recognized [self = 0x350fc0]

The only method I call in NSEntityDescription is in these two consecutive lines of code (in my awakeFromNib on the table data source object):

restrictions = [NSEntityDescription entityForName:@"Restriction" inManagedObjectContext:ctx];
qualifiers = [NSEntityDescription entityForName:@"Qualifier" inManagedObjectContext:ctx];



I don't call a method called "entity" on anything anywhere in the code.

Am I missing anything obvious in the above lines (that method is documented, and the compiler OK'd it), or where would I begin debugging this?


"Restriction" in this case is the "A" from below, and "Qualifier" is the "B".


I can add to the list of "Qualifiers", but upon doing so, the interface locks up if I attempt to switch to the tab with the table view using my data source...

In fact, I just noticed that if I switch from that tab, then back, whether there are any entries or not, it locks up...


I also see a few of these in the log:

malloc: *** Deallocation of a pointer not malloced: 0xbfffd8a0; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug


But I don't do any retain (should I? I am setting these as member variables of the class, and using them in the other methods later on), release, malloc, free, etc...



I'm sorry if any of this seems obvious, but I'm still learning Cocoa while trying to do this!


Thank you!



On Apr 25, 2007, at 9:47 PM, mmalc crawford wrote:


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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Many-To-Many Relationship Interface in Core Data
      • From: mmalc crawford <email@hidden>
References: 
 >Many-To-Many Relationship Interface in Core Data (From: "Frank D. Engel, Jr." <email@hidden>)
 >Re: Many-To-Many Relationship Interface in Core Data (From: mmalc crawford <email@hidden>)

  • Prev by Date: Re: Cannot get toolbar to appear in window
  • Next by Date: drawing red text for some cells while editting in NSTableView
  • Previous by thread: Re: Many-To-Many Relationship Interface in Core Data
  • Next by thread: Re: Many-To-Many Relationship Interface in Core Data
  • Index(es):
    • Date
    • Thread