Re: ArrayController vs Pop-up button vs Transformer -- three way tag team death match!
Re: ArrayController vs Pop-up button vs Transformer -- three way tag team death match!
- Subject: Re: ArrayController vs Pop-up button vs Transformer -- three way tag team death match!
- From: Ben Golding <email@hidden>
- Date: Wed, 20 Apr 2011 17:25:20 +1000
On 20/04/2011, at 15:41, Ken Thomases wrote:
> On Apr 19, 2011, at 8:46 PM, Ben Golding wrote:
>
>> I should have been more specific. What I have looks like:
>>
>> popupButton.content -(Transformer)-> [arrayController].arrangedObjects
>> popupButton.selectedIndex --> [arrayController].selectionIndex
>>
>> I have also tried:
>>
>> popupButton.contentValues -(Transformer)-> [arrayController].arrangedObjects
>> popupButton.selectedIndex --> [arrayController].selectionIndex
>
> You can't bind contentValues without also binding content, and contentValues should be bound to something "within" the content binding. (That is, the binding should be the same as for content except perhaps with additional elements to its model key path.)
I tried doing both together with no change.
As an aside, IB doesn't seem to have an problem with just binding contentValues (ie, with content unbound). Other places where there are these sorts of dependencies, IB doesn't allow you to make the binding/connection.
>> In both cases, the transformer is passed an _NSControllerArrayProxy object which wasn't what I was hoping for; I had hoped for an NSString. I could probably dredge around in that object and find some methods to use but all the docs say "don't use undocumented methods/classes" so my gut reaction is to try another way.
>
> Have you tried setting a model key path? How about "description"?
Yes.
> People often try binding, via array controllers, to arrays of values, and then want those values represented in the view. It is my experience that bindings work better with arrays of objects, with a property of each object to be represented in the view.
Trouble is that what I'm trying to model really is an array of strings.
To put this problem into context, what I'm trying to offer the user through the pop-up button is which character to use as a field separator when reading a CSV file. The value transformer is something that can recognise a string that isn't visible (TAB for example) and put some sort of visible representation in the button string. What I'm trying to do is to keep the strings unchanged in the content array and just change the presentation on the button so I don't have to translate to and from the printable representation.
> In other words, an array of strings is often problematic, whereas an array of, for example, People objects, which have a "name" property which is a string, works better.
I completely agree and if that was what I had, I'd use that.
> You can pretend the former case is more like the latter by using a model key path like "description" or even "self", although the latter case still tends to be more amenable to bindings.
I've just tried using self and description on the contentValues binding and the array (an NSCFArray this time) is what's passed to the value transformer.
I'm really close to going back to the "old" way which disappoints me. The help here has been great.
Ben.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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