First thanks for all the help to date.  I'm learning a great deal.
The current problem:
I have a model for which I cannot seem to figure out the correct key paths for binding.

My doc has a rooms array (of Rooms) and a courses array (with NSArrayControllers). Each course has a roomConstraint, which contains a roomCosts array of RoomCosts each of which has a Room*, "room" (points to an element of the doc's rooms array) and a "cost" (float).

I can easily bind a table column to the rooms array. I am trying to bind two table columns to the RoomCosts data fields (each Room is basically a NSMutableString for now). They change depending on the currently selected course in a separate tableview.

Earlier, I could make this work in a kludgy way, by creating an intermediary NSArrayController (selectedCourseRoomCosts) whose contentArray was bound to courseController.selection.roomConstraint.roomCosts, and then binding the table columns to selectedCourseRoomCosts.arrangedObjects.room.name and selectedCourseRoomCosts.arrangedObjects.cost

When creating each Course object, I would copy the rooms array into the roomConstraint. Fine. I have no problem keeping that array in sync with the master rooms array.

The problem is, when I add a new Room to the master rooms array, and then add that room to the roomCosts array of each Course's roomConstraint, the table column doesn't get updated, until I tweak it manually (by adding a new course). It is still bound to the existing items in the rooms array - if I alter their name, that get observed and reflected in the table, but adding new ones does not get observed.

Here is some of the relevant code (note that everything is shown here as an ivar, but they are all properties as well):
@interface ClassSchedulerDoc : NSDocument
{
        IBOutlet NSArrayController      *courseController;
        IBOutlet NSArrayController      *roomController;
        NSMutableArray                          *rooms;
        NSMutableArray                          *courses;
}

@implementation RoomArrayController
- (void) addObject:(id) newObject {
[snip]
        // Add the object to the rooms array of each course
        [courseController addRoom:newObject];
}

@implementation CourseArrayController
- (void) addRoom:(Room *) newRoom {
        for (Course *curCourse in [self arrangedObjects]) {
                [curCourse addRoom:newRoom];
        }
}

@interface CourseRoomConstraint : Constraint {
        NSMutableArray * roomCosts; // array of RoomCosts
}

@implementation CourseRoomConstraint
- (void) addRoom:(Room *) newRoom {
        [roomCosts addObject:[[RoomCost alloc] initWithRoom:newRoom]];
}

@interface RoomCost : NSObject <NSCoding> {
Room *room; // this is a pointer to the real object in the real Rooms array - a weak reference
        float cost;
}

Thanks in advance,
Dave

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to