Re: NSPopupButton in main window changes when NSUserDefaultsController adds/removes item in Preference Pane
Re: NSPopupButton in main window changes when NSUserDefaultsController adds/removes item in Preference Pane
- Subject: Re: NSPopupButton in main window changes when NSUserDefaultsController adds/removes item in Preference Pane
- From: Matt Neuburg <email@hidden>
- Date: Wed, 04 Jul 2007 08:45:17 -0700
- Thread-topic: NSPopupButton in main window changes when NSUserDefaultsController adds/removes item in Preference Pane
On Wed, 4 Jul 2007 07:13:01 +1000, Tony Kambourakis
<email@hidden> said:
>Hi Matt,
>
>I set the NSPopupButton selectItem to nil in awakeFromNib in my view
>controller.
But an NSPopupButton should never have no selection. Er, I mean, it should
always have some selection - exactly one item should always be chosen.
Otherwise the popup will be blank, which is wrong. If you want there to be a
None option, add it to the list of possibilities as an explicit menu item.
>So when the main screen appears, the NSPopupButton is prefilled with
>the content from NSUserDefaults but shows an empty selection.
>
>However, if the user opens the Preferences window and changes the
>content of the NSUserDefaults via a Preference NSTableView (just a
>list of items), for some reason the selection of the NSPopupButton is
>automatically set to the first in the list. This happens whether I
>add or remove an item from the Preference window.
>
>If I bind the selectedIndex to something, won't I lose the ability
>for the user to change the selection?
If you think that, you don't understand what a binding is. Maybe you should
just experiment in a tiny project, to teach yourself how this thing works,
before applying this technique to your actual app. (That's what I always
do.) Or maybe you would be better off not using bindings at all. After all,
they didn't always exist, and we all got along just fine back then.
> And what would I bind it to?
Whatever you like. You should do whatever is simplest and works best for
your needs.
In my NotLight app, for example, I have a popup which the user can add items
to. The added items are stored in user defaults, so that we remember them
the next time we run this app. But the popup's content is not bound to that
list; the popup's content is bound to an array controller, which is
repopulated manually whenever the user makes a change in the list. The
popup's selection, on the other hand, *is* bound into the user defaults, so
that it is remembered the next time we run this app, and also so that it
maintains itself in a sensible way after the user adds to or removes from
the list.
Also, to repeat:
<http://www.cocoabuilder.com/archive/message/cocoa/2006/5/31/164724>
m.
>On 04/07/2007, at 3:42 AM, Matt Neuburg wrote:
>
>> On Tue, 3 Jul 2007 11:33:05 +1000, Tony Kambourakis
>> <email@hidden> said:
>>>> I have an NSPopupButton in my main application window that is bound
>>>> to an NSArrayController which in turn is bound to the Defaults
>>>> Controller (NSUserDefaultsController) point to that list of items.
>>>>
>>>> I initially set the NSPopupButton to "unselect" items so that even
>>>> though it has content via the bindings to the default list of items,
>>>> it shows a blank item as nothing is selected.
>>>>
>>>> As soon as I add/remove an item in the Preference window table, for
>>>> some reason the NSPopupButton selects the first item on its list. I
>>>> would rather the user make the selection. I don't know why the
>>>> NSPopupButton updates itself like that. Why would the selection
>>>> of an
>>>> item in NSPopupButton be linked to the process of adding/removing an
>>>> item to the NSUserDefaultsController?
>>
>> You evidently imply above that the popup button's *content* is
>> bound. But
>> what about the popup button's *selection*? It needs to get
>> selectedIndex
>> info from somewhere. m.
>>
>> --
>> matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
>> A fool + a tool + an autorelease pool = cool!
>> AppleScript: the Definitive Guide - Second Edition!
>> <http://www.amazon.com/gp/product/0596102119>
>>
>>
>>
>
>
>
>
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
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