Re: KVC with bindings to array elements?
Re: KVC with bindings to array elements?
- Subject: Re: KVC with bindings to array elements?
- From: Jeff Koftinoff <email@hidden>
- Date: Fri, 20 Oct 2006 11:21:39 -0700
On 20-Oct-06, at 10:34 AM, Hank Heijink wrote:
Cocoa is right - you can't convert an NSArray to an NSDictionary
just like that. Do you mean that you absolutely *have* to use an
array? If so, the dictionary idea isn't going to work.
No, I do not have to use an NSArray... The NSDictionary can work just
fine for me..
What I meant was something like this: in your object, have an
instance variable like this:
NSDictionary *someDictionary;
The stuff that you want to bind your UI controls to would be in
there, so that
[someDictionary valueForKey:@"someKey"]
will give you the value you want to have in the control. Then you
bind the control to someDictionary.someKey, and that should do it.
I did that - Created a dictionary.
My class has the intance variable:
NSDictionary *myFader;
I create it and initialize it with dummy data. Each item in the
dictionary is an object with a float 'value'.
In my object I can do:
NSLog( @"Value for key 1: %@", [ myFader valueForKeyPath:
@"1.value" ] );
And it does print out:
2006-10-20 11:16:39.301 MacTest[3968] Value for key 1: 1
But then the nib file loads
(gdb) continue
2006-10-20 11:16:39.439 MacTest[3710] An uncaught exception was raised
2006-10-20 11:16:39.453 MacTest[3710] Cannot create NSArray from
object {
0 = < MyFader: 0x37b1c0>;
1 = < MyFader: 0x37b290>;
10 = < MyFader: 0x37b370>;
.... etc..
} of class NSCFDictionary
What am I doing wrong?
Thanks in advance
jeff
Hank
On Oct 20, 2006, at 1:20 PM, Jeff Koftinoff wrote:
Thank you for your response; But I still have a problem. I can't
just have my accessor method return an NSDictionary - Cocoa
expects it to be an NSArray, and I get an exception saying it
can't convert the NSDictionary to the NSArray. I also tried
implementing a method named:
valueIn<Key>WithName
But it does not get called.
Jeff
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden