• 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
getting started on bindings => problems with NSMutableArray - NSArrayController - NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getting started on bindings => problems with NSMutableArray - NSArrayController - NSTableView


  • Subject: getting started on bindings => problems with NSMutableArray - NSArrayController - NSTableView
  • From: Colin Howarth <email@hidden>
  • Date: Sun, 20 Sep 2009 22:51:24 +0200

Hi all,

I've tried various searches, Apple documentation and example code, but my code stubbornly refuses to work :-(

I'm trying to do this in conjunction with Interface Builder...


I have an instance of an NSMutableArray of LensElements in my AppDelegate.


I have an NSArrayController in the MainMenu.xib IB window.

My main window has an NSTableView.

I'd like the NSTableView to display the data of the array of LensElements. Later I'd like to be able to drag elements within my custom LensView, and have this update the TableView. Also, changing data within the TableView should update the LensView. But, for now, I'd be happy if the Table would simply display the data. (grrrr)

It's really frustrating. The examples I find either don't seem to fit what I'd like to do (NSMutableArray - NSArrayController - NSTableView). And/or they use ancient versions of IB (which keeps changing). Or they don't use IB at all. Or, like me, they just mention some settings, but ignore others - like "Table View Attributes >> Control >> State: Enabled" or "Array Controller Attributes >> Object Controller >> Editable (yes)". Sometimes I see columns bound. Sometimes ControllerKey is "selections" sometimes it's "arrangedObjects". And nothing works. The documentation only makes sense when you know exactly what it's talking about. :-(


Please unconfuse me. I only need to get "into" this once, then I'll be OK. Honest.




In Interface Builder:

###################################################################

Trace App Delegate Connections:
	Referencing Bindings:
		elements --- Content Array / Array Controller


###################################################################

Table Column (position) Attributes:
	Table Column:
		Title: Z position
		Identifier: position

Table Column (position) Bindings:
	Value:
		Bind To: Array Controller
		Controller Key: selection		// tried arrangedObjects
		Model Key Path: position

Table Column (position) Connections:
	Bindings:
		 Value -- Array Controller / selection.position

###################################################################

Array Controller Attributes:
	Object Controller:
		Mode: "Class"
		Class Name: "LensElement"

Array Controller Bindings:
	Controller Content:
		Bind To: Trace App Delegate
		Model Key Path: elements

Array Controller Connections:
	Bindings:
		Content Array --- Trace App Delegate / elements
	Referencing Bindings:
		selection.position --- Value / Table Column (position)
		selection.radius --- Value / Table Column (radius)

###################################################################


Here are the snippets of code (#imports etc included).

The app compiles without errors or warnings and runs fine. All my views and buttons etc show up fine, but the NSTableView doesn't show any content. Well, it did once, when there was only one LensElement in the array :-) I then added another, as you can see below, and it stopped showing anything. I removed it again and it hasn't worked since... (???)


### LensElement.h ####################################################

@interface LensElement : NSObject
{
	NSNumber	*position;
	NSNumber	*radius;
}

@property (copy, nonatomic) NSNumber	*position;
@property (copy, nonatomic) NSNumber	*radius;

@end

### LensElement.m ####################################################

@implementation LensElement

@synthesize position; // creates the proper getter and setter methods?
@synthesize radius;


@end

### TraceAppDelegate.h# ###############################################

@interface TraceAppDelegate : NSObject <NSApplicationDelegate> {
	NSWindow		*window;
	NSMutableArray	*elements;
	NSArrayController	*ctrlr;
}

@property (assign) IBOutlet NSWindow *window;
@property (assign) NSMutableArray  *elements;

@end

### TraceAppDelegate.m ###############################################

@implementation TraceAppDelegate

@synthesize window; // creates the proper getter and setter methods?
@synthesize elements;


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

LensElement *element = [[LensElement alloc] init]; // this is just for testing...
LensElement *element2 = [[LensElement alloc] init];


elements = [[NSMutableArray alloc] initWithObjects:element, element2, nil];

[element setValue: [NSNumber numberWithDouble: 5.0] forKey:@"position"];
[element setValue: [NSNumber numberWithDouble: 10.0] forKey:@"radius"];


[element2 setValue: [NSNumber numberWithDouble: 6.0] forKey:@"position"];
[element2 setValue: [NSNumber numberWithDouble: -15.0] forKey:@"radius"];


NSLog(@"pos: %@", [[elements objectAtIndex:1] valueForKey:@"position"] ); // prints 6.0, as it should

	...
####################################################################
_______________________________________________

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: getting started on bindings => problems with NSMutableArray - NSArrayController - NSTableView
      • From: Quincey Morris <email@hidden>
    • Re: getting started on bindings => problems with NSMutableArray - NSArrayController - NSTableView
      • From: Sean Kline <email@hidden>
  • Prev by Date: Architecture for concurrent network client
  • Next by Date: Job Posting: Experienced Cocoa User Interface Developer (full time position, New York City)
  • Previous by thread: Re: Architecture for concurrent network client
  • Next by thread: Re: getting started on bindings => problems with NSMutableArray - NSArrayController - NSTableView
  • Index(es):
    • Date
    • Thread