NSPopupButton Bindings-Related Issue

2008-06-27 Thread Keary Suska
Generally, my needs are simple. In this case, I need a sheet that displays
an nspopupbutton populated with product names, where a user can select an
item from the popup and a description of the item would appear in a
designated space below the control, and of course I want to retrieve the
value after the sheet is dismissed, providing that the correct button is
pressed. Sounds easy, right?

So, I have an NSPanel with an NSPopupButton, NSTextField, and two buttons
("Cancel" and "Use"). The NSPopupButton "content" is bound to
"ProductController", which is a special NSArrayController subclass whose
content is an array objects I am interested in, with key "arrangedObjects"
no key path. "Content values" is bound to same with key path "name".
"Selected value" is bound to same but with controller key "selection" and
key path "name". NSTextField "value" is bound to ProductController
"selection" key path "descrip".

Okeydoke. BTW, there are some popup items that I want disabled, so I turn
off autoenableitems in awakeFromNib and disable them before I display the
sheet. Peachy keen cool. Popup appears as expected. However, when I select
an item, the NSTextField doesn't update. Furthermore, all of the disabled
items automagically enable (that's bad too). Crazy, huh?

Any ideas, anyone?

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


___

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 [EMAIL PROTECTED]


Re: NSPopupButton Bindings-Related Issue

2008-06-27 Thread Ken Thomases

On Jun 27, 2008, at 11:01 PM, Keary Suska wrote:

Generally, my needs are simple. In this case, I need a sheet that  
displays
an nspopupbutton populated with product names, where a user can  
select an

item from the popup and a description of the item would appear in a
designated space below the control, and of course I want to retrieve  
the
value after the sheet is dismissed, providing that the correct  
button is

pressed. Sounds easy, right?

So, I have an NSPanel with an NSPopupButton, NSTextField, and two  
buttons

("Cancel" and "Use"). The NSPopupButton "content" is bound to
"ProductController", which is a special NSArrayController subclass  
whose
content is an array objects I am interested in, with key  
"arrangedObjects"

no key path. "Content values" is bound to same with key path "name".
"Selected value" is bound to same but with controller key  
"selection" and

key path "name". NSTextField "value" is bound to ProductController
"selection" key path "descrip".


The last two bindings are incorrect, I think.  Bind the pop-up's  
Selected Object to a property of your model, not the array  
controller's selection.  That is, when the pop-up has an item  
selected, it will stuff that object (the "product") into that property  
of your model.


Then, binding your text field's Value to that same model property,  
except adding on ".descrip" to the key path.


This sort of arrangement is illustrated in the "Real-World Example" in  
the Cocoa Bindings Programming Topics: .


In that example, the similarity to what I described above is a bit  
obscured by the fact that there's a list of attackers and the pop-up  
is for selecting the weapon of the selected attacker.  So, the pop- 
up's Selected Object binding does go through an array controller's  
selection, but it's not the same array controller which provides the  
content for the pop-up.  Try to imagine that example if there were  
only a single attacker in the model, and therefore the first array  
controller were removed (or replaced by just an NSObjectController).



Okeydoke. BTW, there are some popup items that I want disabled, so I  
turn
off autoenableitems in awakeFromNib and disable them before I  
display the
sheet. Peachy keen cool. Popup appears as expected. However, when I  
select
an item, the NSTextField doesn't update. Furthermore, all of the  
disabled

items automagically enable (that's bad too). Crazy, huh?

Any ideas, anyone?


I don't know what's going on there.

___

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 [EMAIL PROTECTED]


[SOLVED] NSPopupButton Bindings-Related Issue

2008-06-28 Thread Keary Suska
For perpetuity, to do what I wanted I needed to bind selectedIndex to the
controller's "selectionIndex". I was avoiding this because it requires me to
have an outlet to the controller for conditionally enabling/disabling popup
items. Oh well.

Best,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

-- Forwarded Message
> From: Keary Suska <[EMAIL PROTECTED]>
> Date: Sat, 28 Jun 2008 11:15:46 -0600
> To: Ken Thomases <[EMAIL PROTECTED]>
> Conversation: NSPopupButton Bindings-Related Issue
> Subject: Re: NSPopupButton Bindings-Related Issue
> 
> 6/28/08 12:30 AM, also sprach [EMAIL PROTECTED]:
> 
>> On Jun 27, 2008, at 11:01 PM, Keary Suska wrote:
>> 
>>> Generally, my needs are simple. In this case, I need a sheet that  displays
>>> an nspopupbutton populated with product names, where a user can  select an
>>> item from the popup and a description of the item would appear in a
>>> designated space below the control, and of course I want to retrieve  the
>>> value after the sheet is dismissed, providing that the correct  button is
>>> pressed. Sounds easy, right?
>>> 
>>> So, I have an NSPanel with an NSPopupButton, NSTextField, and two  buttons
>>> ("Cancel" and "Use"). The NSPopupButton "content" is bound to
>>> "ProductController", which is a special NSArrayController subclass  whose
>>> content is an array objects I am interested in, with key  "arrangedObjects"
>>> no key path. "Content values" is bound to same with key path "name".
>>> "Selected value" is bound to same but with controller key  "selection" and
>>> key path "name". NSTextField "value" is bound to ProductController
>>> "selection" key path "descrip".
>> 
>> The last two bindings are incorrect, I think.  Bind the pop-up's  Selected
>> Object to a property of your model, not the array  controller's selection.
>> That is, when the pop-up has an item  selected, it will stuff that object
>> (the 
>> "product") into that property  of your model.
> 
> The "selected" binding very well may be wrong. I didn't give the history
> there. If I don't bind anything there, the controller won't maintain a
> selection--i.e. the controller selection never changes. I tried various
> bindings, but I also have the issue of needing a sensible representedObject.
> 
> Anyway, one key, or issue, is that none of this setup is part of a
> relationship, which your description above would apply to. I.e., there is no
> separate model object that wants the selected object. There is only a
> controller that wants it, but only if the user doesn't cancel the dialog.
> 
> It could be that an NSArrayController can only function in a relationship, but
> I was hoping that wasn't necessary. All I want is a simple MVC: my model, an
> array of objects; my view, an NSPopUpButton (and NSTextField on the side); my
> contoller, a simple NSArrayController. BTW, I lied about it being a
> subclass--it's just a vanilla NSArrayController.
> 
> I just want the array controller to do its job--maintain a selection that I
> can get later.
> 
>> Then, binding your text field's Value to that same model property,  except
>> adding on ".descrip" to the key path.
> 
> No, this would be incorrect. View should always bind to a controller, and I
> shouldn't need an additional one. My binding is a typical type used in a
> master-detail interface.
> 
>> This sort of arrangement is illustrated in the "Real-World Example" in
>> the Cocoa Bindings Programming Topics:
>> 
<http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Conc>>
e
>> pts/WhatAreBindings.html#//apple_ref/doc/uid/20002372-181136
> 
> This shows the binding that I am currently sing, BTW. Anyway, I should
> probably start googling for implementing a maser-detail interface using
> NSPopupButton, which seems to involve some sort of trickery.
> 
> Thanks for the assist,
> 
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"

-- End of Forwarded Message


___

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 [EMAIL PROTECTED]