Well, simple for you guys I hope!

I apologize in advance for this monstrosity of a question, but I've had a tough time narrowing this thing down so I'm laying out all the details to keep the thread short in hopes that someone will spot an obvious mistake right away. Any help greatly appreciated!

I've been trying to build a simplified implementation of the combatants example in the Cocoa Bindings Programming Topics doc to prove that I really understand Array Controllers and Binding. Apparently, I do not!

My goal is to get two array controllers (master/detail) working together in a simple non-doc cocoa app. How hard could that be? Versions I am working with [10.5.8 / Xcode 3.1.3]

I have the master ac bound to its model class (Combatant) creating and deleting entries no problem. All the trouble started when I created the detail ac for (Weapon) and tried to bind it to the master ac. The app starts up without any errors or warnings at first.

I create two combatants, "Vlad" and "Atilla" in the master table, no problem. Now I cursor up and select "Vlad" in the first row and BAM stack trace. What! Unbind the detail ac in the XIB and the master table works perfectly adding/deleting/selecting/name changing. To further simplify, I have not yet attached a gui element to the detail ac.

I can't make a lot of sense out of the stack trace, but it does end with:
0 objc_msgSend
1 objc_getProperty
2 -[Combatant weapons]
3 -[NSObject(NSKeyValueCoding) valueForKey:]
4- [NSObject(NSKeyValueCoding) valueForKeyPath:]
leading me to wonder if I did something wrong with my accessors. Please pardon the newbie confusion!

Data elements and settings for the ac's follow:

Classes:
App Controller
        NSMutableArray *combatants
Combatant
        NSString *name
        NSMutableArray *weapons
Weapon
        NSString *name
(code further below if you want to see it all)

Array Controllers:

Master Combatants
Attributes panel
        Mode:Class, Class Name: Combatant, Key:name, weapons
Bindings panel
        Content Array
Bind to: App Controller, Controller Key <empty>, Model Key Path: combatants (and I do have an App Controller object in the MainMenu.xib with the AppController name set in the identity panel)

Detail Weapons
Attributes panel
        Mode:Class, Class Name: Weapon, Key:name
Bindings Panel
        Content Array
Bind to: Master Combatants, Controller Key: selection, Model Key Path: weapons

The intention is to bind a Popup or even just a Table with a name column to the Detail Weapons ac once I eliminate the runtime error.

Honestly, I wouldn't be posting all this if I hadn't been banging my head against the wall, googling, reading tutorials, trying dozens of variations before getting so desperate I actually ask for help! I'm going to feel so stupid when you point out what I did wrong.

- Leon

 THE CODE

// AppController

@interface AppController : NSObject {
        NSMutableArray *combatants;
}
@property (readwrite, retain) NSMutableArray *combatants;
@end

@implementation AppController
@synthesize combatants;
- (id)init{
        [super init];
        combatants = [[NSMutableArray alloc] init];
        return self;
}
- (void) dealloc{
        [combatants release];
        [super dealloc];
}
@end

// Combatant
@interface Combatant : NSObject {
        NSString *name;
        NSMutableArray *weapons;
}
@property (readwrite, copy) NSString *name;
@property (readwrite, retain) NSMutableArray *weapons;

@end

@implementation Combatant
@synthesize name;
@synthesize weapons;
- (id)init{
        [super init];
weapons = [NSMutableArray arrayWithObjects:@"Dagger", @"Sword", @"Pike", nil];
        return self;
}
@end

// Weapon
@interface Weapon : NSObject {
        NSString *name;
}
@property (readwrite, copy) NSString *name;
@end

@implementation Weapon
@synthesize name;
@end



_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to