[SOLVED] Re: NSOutlineView with multiple Core Data entities
[SOLVED] Re: NSOutlineView with multiple Core Data entities
- Subject: [SOLVED] Re: NSOutlineView with multiple Core Data entities
- From: Matthew Lindfield Seager <email@hidden>
- Date: Fri, 11 Sep 2009 05:13:53 +1000
On 09/09/2009, at 2:28 PM, Brent Gulanowski wrote:
Here's one option. I think it's your second one. Was easier to do than to
try to explain it. Plus less chance I describe it wrong.
Thank you so much Brent! The combination of adding ArrayController outlets
to the AppDelegate and then returning the ArrayControllers' arrangedObjects
by index when the children are requested by the Data Source methods was
exactly what I was after!
It seems quite easy and obvious with the benefit of hindsight but so do a
lot of things!
On 09/09/2009, at 10:34 PM, Richard Somers wrote:
Have you looked at Apple's AbstractTree sample code?
https://developer.apple.com/mac/library/samplecode/AbstractTree/index.html
Thanks for the reply and the link Richard but it was actually the details of
having multiple different entity types display in the one NSOutlineView that
was tripping me up.
The code below is a summary of the methods Brent provided that I added to
the standard XCode generated AppDelegate to get this working (it's hard
coded to two items and not abstract enough to scale particularly well but
it's all I needed).
//
// CoreDataSourceListAppDelegate.m
// CoreDataSourceList
//
// Created by Brent Gulanowski on 09-09-08.
// Copyright 2009 Marketcircle Inc. All rights reserved.
//
#import "CoreDataSourceListAppDelegate.h"
#define CDSL_PARENT_GROUP_1 @"Parent Group 1 Title"
#define CDSL_PARENT_GROUP_2 @"Parent Group 2 Title"
@implementation CoreDataSourceListAppDelegate
- (void)awakeFromNib {
[parentGroup1ArrayController setManagedObjectContext:managedObjectContext];
[parentGroup2ArrayController setManagedObjectContext:managedObjectContext];
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index
ofItem:(id)item {
if(nil == item)
if(0 == index)
return CDSL_PARENT_GROUP_1;
else if(1 == index)
return CDSL_PARENT_GROUP_2;
if([item isEqual:CDSL_PARENT_GROUP_1])
return [[parentGroup1ArrayController arrangedObjects] objectAtIndex:index];
if([item isEqual:CDSL_PARENT_GROUP_2])
return [[parentGroup2ArrayController arrangedObjects] objectAtIndex:index];
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
if([item isEqual:CDSL_PARENT_GROUP_1] || [item
isEqual:CDSL_PARENT_GROUP_2])
return YES;
return NO;
}
- (NSInteger)outlineView:(NSOutlineView *)outlineView
numberOfChildrenOfItem:(id)item {
if(nil == item)
return 2;
if([item isEqual:CDSL_PARENT_GROUP_1])
return [[parentGroup1ArrayController arrangedObjects] count];
if([item isEqual:CDSL_PARENT_GROUP_2])
return [[parentGroup2ArrayController arrangedObjects] count];
return 0;
}
- (id)outlineView:(NSOutlineView *)outlineView
objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
if([outlineView levelForItem:item] == 0)
return item;
return [item valueForKey:@"outlineDisplayName"];
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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