• 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
Need help programatically wiring up an NSTreeController to an NSOutlineView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Need help programatically wiring up an NSTreeController to an NSOutlineView


  • Subject: Need help programatically wiring up an NSTreeController to an NSOutlineView
  • From: Ken Tozier <email@hidden>
  • Date: Thu, 30 Oct 2008 14:47:09 -0400

Hi

I've been Googling bindings, and reading the Apple bindings documentation for a week, but have gotten nowhere on this one. I desperately need help from someone who knows programmatic bindings.

I have a class where I store all properties in an NSMutableDictionary and wrote a few accessors to make it simpler to access some of the items stored in the dictionary. The program compiles without errors and runs fine until I try to programatically add new instances of the class to a bound NSMutableArray, which is giving me the following error:

-[NSCFArray _valueForKeyPath:ofObjectAtIndexPath:]: unrecognized selector sent to instance 0x11d29350

If anyone could point out where I'm screwing up in the example code below it would be hugely appreciated.

Thanks in advance.



Here's what the stripped down class looks like:

----------------------------------------------------------------------

@interface PMProject : NSObject
{
	NSMutableDictionary *properties;
}

// Name accessor
- (NSString *) name;

// Required NSTreeController methods
- (NSArray *) children;
- (BOOL) isLeafNode;

@end

@implementation PMProject

- (id) init
{
	self = [super init];
	if (self)
	{
		properties = [[NSMutableDictionary alloc] init];

		[properties setObject: @"CO_01-05" forKey: @"display_name"];
		[properties setObject: [NSArray array] forKey: @"children"];
	}

	return self;
}

- (NSString *) name
{
	NSLog(@"Entered: MyProject: name");
	return [properties objectForKey: @"display_name"];
}

- (NSArray *) children
{
	NSLog(@"Entered: MyProject:children");
	return [properties objectForKey: @"children"];
}

- (BOOL) isLeafNode
{
	NSLog(@"Entered: MyProject:isLeafNode");
	return ([[self children] count] == 1) ? YES : NO ;
}

@end

----------------------------------------------------------------------

A higher level object (PMController ) contains an NSMutableArray property which stores a collection of "PMProject" objects and an NSTreeController property to serve as the intermediary between the NSMutableArray and an NSOutlineView.

I'm setting up the NSTreeController like so:

- (void) initTableController
{
tableController = [[NSTreeController alloc] initWithContent: nil];
[tableController setChildrenKeyPath: @"children"];
[tableController setLeafKeyPath: @"isLeafNode"];
// NOTE: PMController is a singleton class that stores an
// NSMutable array of currently open PMProject objects
[tableController bind: @"contentArray" toObject: [PMController sharedController] withKeyPath: @"currentProjects" options: nil];
}


And am trying to bind the "name" column of the NSOutlineView to the NSTreeController like this

- (void) initMyProjectOutline
{
// create text cell
nameCell = [[NSTextFieldCell alloc] init];

// create the name column
nameColumn = [[NSTableColumn alloc] initWithIdentifier: @"name"];
[nameColumn setDataCell: nameCell];
[nameColumn setMinWidth: 1000];
// bind value to MyProject:name accessor
// NOTE: I've tried both of the following but am getting nothing in the NSOutlineView "name" column
[nameColumn bind: @"value" toObject: tableController withKeyPath: @"content.name" options: nil];
[nameColumn bind: @"value" toObject: [tableController content] withKeyPath: @"name" options: nil];

// create the table
table = [[NSOutlineView alloc] initWithFrame: tableFrame];
[table addTableColumn: nameColumn];
[table setHeaderView: nil];
[table setAutoresizingMask: NSViewWidthSizable | NSViewMaxYMargin];
[table setUsesAlternatingRowBackgroundColors: YES];
[table setFocusRingType: NSFocusRingTypeNone];
[table setColumnAutoresizingStyle: NSTableViewLastColumnOnlyAutoresizingStyle];
[table bind: @"content" toObject: tableController withKeyPath: @"content" options: nil];

[self addSubview: table];
}



_______________________________________________

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


  • Follow-Ups:
    • Re: Need help programatically wiring up an NSTreeController to an NSOutlineView
      • From: Ron Lue-Sang <email@hidden>
  • Prev by Date: Re: NSOperationQueue broken?
  • Next by Date: Re: NSOperationQueue broken?
  • Previous by thread: Re: Delegation across thread
  • Next by thread: Re: Need help programatically wiring up an NSTreeController to an NSOutlineView
  • Index(es):
    • Date
    • Thread