Re: Is there a key path for this?
Re: Is there a key path for this?
- Subject: Re: Is there a key path for this?
- From: Quincey Morris <email@hidden>
- Date: Sat, 28 Nov 2009 15:26:52 -0800
On Nov 28, 2009, at 14:45, David Hirsch wrote:
> My document class has an array of Instructors, with a controller. Each instructor has a timeConstraint, which in turn has an array of NSNumbers. I have an NSTableView bound to the Instructor array, and I would like to show the mondayCosts array of floats in another TableView, which will change when the selection in the instructor table changes. Below are bits of the headers. (I have @synthesized each of the properties in the implementation files)
>
> I can get the selection, including other fields of the selected Instructor. I've tried making another NSArrayController in IB with its content bound to instructorController.selection.timeConstraint.mondayCosts, and binding the table column to that, but even if that works, then it's not clear to me how to get the floats out of the NSNumbers.
>
> @interface ClassSchedulerDoc : NSDocument
> {
> IBOutlet NSArrayController *instructorController;
> NSMutableArray *instructors;
> }
>
>
> @interface Instructor : NSObject <NSCoding> {
> }
> @property (retain) ProfTimeConstraint *timeConstraint;
>
>
> @interface ProfTimeConstraint : Constraint {
> }
> @property (retain) NSMutableArray *mondayCosts; // floats within NSNumbers
As far as it goes, it looks like you're doing the right thing. The table column can be bound to the MondayCosts NSArrayController, with either no model key, or a model key of "self". (They mean the same thing.) You likely don't have to "get the floats out of the NSNumbers" yourself:
If the table column has a plain text cell, then the value to be displayed will be retrieve by sending a 'stringValue' message to the underlying NSNumber object, which should come out as a properly formatted float.
If you don't like the standard formatting, you can add a numeric formatter to the table column cell.
The limitation here is that this only works for *display* of the numbers -- you can't edit them in the table because, with this binding, that would imply modifying the NSNumber's "self" property, which makes no sense (and causes an exception if you try). If you want the table to be editable, the easiest solution is to create a class MondayConstraint (for example) which has a "cost" property that is both gettable and settable. Your ProfTimeConstraint would then have an array of MondayConstraint objects instead of an array of NSNumber objects, and you'd bind the table column to the MondayCosts array controller with key "cost".
HTH
_______________________________________________
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