views:

50

answers:

2

I am trying to get my app to remember the selection of an NSPopUpButton for the next time the App is launched. I tried binding the Selection Index to a NSUserDefaultsController but it has no effect, It doesn't remember the selection for the next launch. What do I need to do?

+1  A: 

I haven't played around with bindings too much, so I can't help you figure out what's going wrong there. I would solve this by saving the -[NSPopUpButton indexOfSelectedItem] to [NSUserDefaults standardUserDefaults] at termination and restoring it at launch.

Dave DeLong
+2  A: 

Binding the selected index to the shared NSUserDefaultsController works for me. You need to ensure you set the Controller Key to values and the Model Key Path to a unique preferences key string, such as widgetPopupSelectionIndex.

Also, make sure that you are not exiting your app by clicking the Stop button in Xcode, because defaults are synchronized during the application termination process and if you just kill the app from Xcode the app doesn't get the opportunity to persist the user defaults.

This is a problem that often bites me when I'm working on user defaults-related code. If you quit your app from the application menu in the app then the user defaults should be stored correctly.

Rob Keniger
That is odd, it's still not working for me as you can see here, http://drp.ly/la22h
Joshua
The movie was interesting because I could see the source code. I suspect the problem is that you're binding the selected index but not the values of the popup. I think that the binding is being resolved before you populate the contents of the popup and because at that point the popup is empty, the selection doesn't change. Try creating an `NSArray` ivar to store the list of font name string, expose it as a property and then initialize the ivar in `-init`. You could then bind the **Content Values** of the popup to that array property.
Rob Keniger
Here's what I have now. My Header file www.kttns.org/jjlm . My Implementation File www.kttns.org/mzin2 . But now it won't even populate it just gives me this error www.kttns.org/gi3nj .
Joshua