• 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: NSTreeController / CoreData question [Solved]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTreeController / CoreData question [Solved]


  • Subject: Re: NSTreeController / CoreData question [Solved]
  • From: Justin Fagnani <email@hidden>
  • Date: Tue, 24 May 2005 15:46:22 -0700

On May 24, 2005, at 2:38 PM, Scott Stevenson wrote:
*Subclass NSManagedObject for Category and use a recursive method
for getting all the items.


I think this is probably your best bet.

I just got his working. I had some problems because I implemented the accessors with Arrays instead of Sets, but got past that. So, in case anyone else want to know...


I created a Category class with an -(NSSet)allItems method that does the recursion. I also created two new array controllers. One is BrowsedItems and it's contentArray is bound to selection.allItems. The other array controller is CurrentItems with is just bound to selection.items. The idea is that I want to display all the items in the subtree, but if I modify anything I just want to modify the contents of the currently selected category.

Now I need to figure out how to display all the items when there is no selection. I'm thinking that instead of using a "parent == nil" predicate for the tree controller that I should make a root category and somehow have that be selected when the browser has no selection.

I also added some code in initialize to be notified of changes to items or children. Like this:

+ (void)initialize {
if (self == [Category class]) {
NSArray *keys = [NSArray arrayWithObjects:@"children", @"items", nil];
[self setKeys:keys triggerChangeNotificationsForDependentKey:@"allItems"];
}
}


The thing that concerns me though is if the graphs gets modified down the tree I need to notify all the ancestor categories. I think that means I need to implement some change notification methods, but I know nothing about that at the moment. It's not really much of a problem now since I only have one view, and if I'm editing a category I have it selected and its getting the notification, but in a multi- window setup is could be an issue.

(responding to myself)

Another options is to create a "topLevelCategory" attribute and
override the set mutators for Category, so that every time an item is
added, you can do something like:

     [item setValue: [self valueForKey:@"topLevelCategory"] forKey:
@"topLevelCategory"]];

Then you can add a fetched property to Category for all items that
match "topLevelCategory == %@", self.

Even though I got it working, I'm still interested in what you are saying here. Unfortunately, I don't think I understand what's happening here. It looks like topLevelCategory points to exactly what the name says, but if I selected a 3rd level category I'd still get all the items from it's top-level category, not the items from the selected categories descendants.


Thanks,
  Justin
_______________________________________________
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: NSTreeController / CoreData question [Solved]
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: FYI: User feedback for LSMinimumSystemVersion
  • Next by Date: Re: Grouping undo-able actions with CoreData
  • Previous by thread: Re: NSCalendar: does the thing work at all? Or am I just blind?
  • Next by thread: Re: NSTreeController / CoreData question [Solved]
  • Index(es):
    • Date
    • Thread