Binding Error (accessing value for key) - but works with debugging on
Binding Error (accessing value for key) - but works with debugging on
- Subject: Binding Error (accessing value for key) - but works with debugging on
- From: "Jason Kravitz" <email@hidden>
- Date: Fri, 7 Mar 2008 17:19:25 +0100
The following is occurring on Leopard - Garbage Collection set to
required...
I have an Entity with a NSManagedObject class declaration
//**** header
@interface MyEntity : NSManagedObject {
}
@property (readwrite, copy) NSString *origText,*title;
@property (readwrite, copy) NSDate *date;
@end
//**** implementation
@implementation MyEntity
@dynamic origText,title;
@dynamic date;
@end
In Interface Builder, I created an Array Controller that is Mode: Entity ,
Entity name: MyEntity
I created an NSTableView with columns for title and date and an NSTextView
for origText. I embed these two objects inside an NSSplitView. I drag the
content outlet for the array controller to the NSSplitView and set the
bindings as follows...
Table Column 1 - bind to: MyEntity, controller key: arrangedObjects, model
key path: title
Table Column 2 - bind to: MyEntity, controller key: arrangedObjects, model
key path: date
Text View - bind to: MyEntity, controller key: selection, model key path:
origText
I also have an add and remove button that seem to be working as expected
(with actions set to array controllers add and remove respectively)
The first time the app loads, it crashes with an error about messed up
bindings with origText. If I turn on the bindings debug flag (
-NSBindingDebugLogLevel
1), the app will run without crashing and logs this error to console (see
below) and then if I click on any of the objects in the table, it loads the
origText without errors from then on. I suspect that possibly any of these
is the reason...
1) I am really doing things the wrong way since I'm quite new to this stuff
2) it crashes on the first one because there is no selection so nothing for
origText to bind to but then clicking in the table after that works as
expected since the selection is clear so the question is, how to set the
first selected item in table view ?
3) I don't have a proper getter method for origText (yet it seems to get it
OK except on first run so I'm not sure here) and title does not have a
getter and it works fine.
here is the error I get
2008-03-07 16:52:42.788 myapp[4829:10b] Cocoa Bindings: Error accessing
value for key path selection.origText of object <NSArrayController:
0x101f4b0>[entity: MyEntity, number of selected objects: 1] (from bound
object <NSTextView: 0x102d2e0>
Frame = {{0.00, 122.00}, {478.00, 284.00}}, Bounds = {{0.00, 0.00}, {
478.00, 284.00}}
Horizontally resizable: NO, Vertically resizable: YES
MinSize = {478.00, 284.00}, MaxSize = {487.00, 10000000.00}
with object ID 666 in Nib named MainMenu.nib): [<NSSplitView 0x1032700>
valueForUndefinedKey:]: this class is not key value coding-compliant for the
key origText.
on a side note for the patient person still reading this...
I am a bit confused about using dynamic properties and whether I should be
using synthesize to create the setter/getters on these fields. Is it
appropriate (or more importantly, required) to add a line like this to my
MyEntity NSManagedObject?
@synthesize origText,title;
Is it OK to use @synthesize and @dynamic together? I assume so since dynamic
is just telling compiler that these attributes exist...
And finally, even stranger... when I do add the synthesize call to my
NSManagedObject, I see some other odd behavior
1) I get a compiler error about ivars which I got around by declaring these
vars in the header
2) the first time the app runs, the table column does not show the title
field (like it can't access it) but when I click on the table to give it
focus, the titles show up.
I hope I explained all that well enough - there are some odd problems
coupled with a lack of understanding of what I'm doing on my part !
cheers
_______________________________________________
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