Re: Bindings Concept Question
Re: Bindings Concept Question
- Subject: Re: Bindings Concept Question
- From: Chris Hanson <email@hidden>
- Date: Sat, 21 Jun 2008 19:12:04 -0700
On Jun 21, 2008, at 10:49 AM, Alex Wait wrote:
I have tried to, in my init method, to do this
id proxy = [controller mutableArrayValueForKey:@"arrayOfData"];
Your init method of what class?
Does "controller" have an "arrayOfData" property, or does the object
you're making that call from?
-(void)addData: (id) sender
{
NSString* newFirst = [firstNameField stringValue];
NSString* newLast = [lastNameField stringValue];
Data* newData = [[Data alloc]init];
[newData setValue:newFirst forKey:@"firstName"];
[newData setValue:newLast forKey:@"lastName"];
[arrayOfData addObject:newData];
That right there is your problem. You are modifying the array itself,
not the property, so it is not posting KVO notifications.
Replace that with
[[self mutableArrayValueForKey:@"arrayOfData"] addObject:newData];
and observer notifications will be sent.
It's also good to be in the practice -- even when creating example,
test, or throwaway projects -- of using good names for your properties
and classes. You can use Xcode's refactoring support to easily change
the name of the "Data" class to "Person", the "arrayOfData" property
to "people", and the "newData" local variable to "newPerson".
Your code will read much more clearly that way: For example, you
won't be misled to thinking that the underlying array should post
notifications for changes made to it, because it's the property you
really want notifications for.
--- Chris
_______________________________________________
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