Re: Binding to an NSMutableArray
Re: Binding to an NSMutableArray
- Subject: Re: Binding to an NSMutableArray
- From: Lorenzo Thurman <email@hidden>
- Date: Tue, 15 Feb 2011 23:08:50 -0600
On Feb 15, 2011, at 10:42 PM, "Stephen J. Butler" <email@hidden> wrote:
> On Tue, Feb 15, 2011 at 10:37 PM, Lorenzo Thurman <email@hidden> wrote:
>> I have an object, Student, that contains firstName and lastName as instance
>> variables. Student also contains an NSMutableArray of infraction objects
>> that contains NSString's for the infraction name, location, punishment and
>> an NSDate. I want to bind these infraction objects to the columns of an
>> NSTableView. What I've done to make this work is copy the infraction object
>> to another NSArray when the Student is loaded and binding the table columns
>> to the NSArrayController associated with this new array. Obviously, this is
>> suboptimal. It seems to me that I should be able to bind directly to the
>> infraction as it resides in the Student object, but I just can figure out
>> how to bind to a particular index within the NSMutableArray within the
>> Student object. I've looked at some examples here:
>> http://homepage.mac.com/mmalc/CocoaExamples/controllers.html
>>
>> but I didn't find anything quite like what I'm doing. I've gone back through
>> the KVC/KVO documents to see if I'm missing something. Does anyone have any
>> pointers on how I can go about this? If its possible at all.
>
> Assuming that your Students are in an NSArray themselves, and that
> there exists a Students Array Controller, did you try binding the
> Infractions Array Controller to the Students Array
> Controller.selection.infractions?
Yes, the Student objects are in an array themselves managed by an array controller. I did try the keypath you suggest above, but the app crashes on startup with "...not key value compliant..." errors. I've tried various combinations of controller .selectedIndex.infractions, controller selectedIbject.infractions, but nothing works.
I should add that there are 2 tables side by side in the app. On the left, 3 columns, fname, lname bound directly to Student object as controller.fname/lname and the count of infractions in the third column using infractions.@count
On the right, when a student from the left is highlighted, I want to display the infraction name and description for each infraction in the array. So, if it were possible, I would expect the keypath to look something like this:
email@hiddenctionName/description
But clearly that can't be done. _______________________________________________
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