Thanks, Quincy.
There was no error message in the session when I originally submitted
my question. But I just tried running my code (unchanged) this
morning several times and found that SOMETIMES I get an error in the
console just before the stack trace. And it is not always exactly the
same, but the theme is similar. It always involves something about
not being able to create an array. Here's the latest:
Cannot create NSArray from object <NSMutableIndexSet: 0x17d8b0>[number
of indexes: 1 (in 1 ranges), indexes: (0)] of class NSMutableIndexSet
If I change the @property for weapons to (readwrite, copy), from
retain, I get this error:
Cannot create NSArray from object selection of class NSCFString
I have tried running my code as a command line tool (no bindings) and
I don't get any runtime errors, so I am not sure where the memory
issue would be. Any other ideas?
- Leon
On Aug 24, 2009, at 5:43 , [email protected] wrote:
From: Quincey Morris <[email protected]>
Subject: Re: Simple array controller master-detail binding problem
On Aug 23, 2009, at 19:58, Leon Starr wrote:
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:]
You left out the vital piece of information: the error message that
was logged when this occurred. Look in the debugger console window.
(However, if this is an exception, sometimes the exception is thrown
before the error is logged. You may have to continue until the error
message appears.)
According to your stack trace, something is attempting to retrieve the
"weapons" property of a Combatant, which seems perfectly reasonable,
and all your bindings appear reasonable at first glance. The most
likely cause of your problem is a memory management error in your code
-- the Combatant object with name "Vlad" has likely been over-
released. Chances are, when you see the error message, it will tell
you that "weapons" was sent to an object of the wrong class, and that
would pretty much confirm it. (That is, the memory that was previously
a Combatant object has been reused for a different class of object.)
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]