On 19/04/2011, at 18:19, Quincey Morris wrote:

> On Apr 19, 2011, at 00:41, Ben Golding wrote:
> 
>> I am a bit stumped.  I have an array controller which I have hooked up to a 
>> pop-up button and that works quite well.  The members of the array are 
>> NSStrings but I would like to reformat them when they're displayed by the 
>> pop-up button.  Seems fairly straightforward, I thought I'd just write a 
>> little transformer to do that.
>> 
>> I plugged everything together and was surprised that that the transformer 
>> was raising an exception because it was being passed an 
>> NSObjectControllerProxy as its argument, not an NSString as I'd been 
>> expecting.
> 
> Can you list explicitly all the NSPopUpButton bindings you're using?

Sure, I'm using content to bind to an array controller bound to an array of 
pop-up button titles and selected index (though I'm picking up the selected 
object using [[arrayControlled selectedObjects] objectAtIndex:0]).

I've also tried binding to contentValues which was unsuccessful too.

> The bindings for popup buttons are very nasty. You have to figure out 
> what/whether to bind 'content', 'contentObjects' and 'contentValues'. Only 
> after you've got that right can you decide which of the 'selected...' 
> bindings you want to use.
> 
> 'content', 'contentObjects' and 'contentValues' correspond to controller 
> proxies, strings and represented objects, but I couldn't tell you off-hand 
> which corresponds to what. It's anybody's guess whether the documentation 
> (http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CocoaBindingsRef/BindingsText/NSPopUpButton.html)
>  is actually correct -- several of the pages in that document are wrong 
> and/or incomplete -- and it's a puzzle sometimes to understand what the 
> documentation even means.

What I'd found was that the documentation doesn't indicate what the 
ValueTransformer indicated is passed.  It seems to be a controller object, not 
the pop-up button item's title which is the only thing that seems to make sense 
in the context.

> TBH, I've generally found it easier *not* to use bindings for NSPopUpButton 
> content, but provide it the traditional way ('-[NSPopUpButton 
> insertItem...]'), and just use a binding for 'selectedIndex'. But maybe I'm 
> just a coward.

I share your fear but the win with bindings is too good to avoid.  I try to 
think of these sort of frustrations as part of the learning process.  I can 
really sympathise with wanting to fall back to the "old way".

        Ben.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to