0

I've tried numerous things and cannot get it to function...

 [[NSUserDefaults standardUserDefaults] setObject:[my_popup_button selectedItem] forKey:@"selected"];

Does not work, got any suggestions?

Rstew
  • 585
  • 2
  • 9
  • 21

1 Answers1

3

This is from a minimal example I just created:

AppDelegate.h

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSPopUpButton *popupButton;
- (IBAction)onPopupBtnSelectedItemChanged:(id)sender;

@end

AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [self.popupButton selectItemAtIndex:[[NSUserDefaults standardUserDefaults] integerForKey:@"selectedItemIndex"]];
}


- (IBAction)onPopupBtnSelectedItemChanged:(id)sender
{
    [[NSUserDefaults standardUserDefaults] setInteger:self.popupButton.indexOfSelectedItem                            
                                               forKey:@"selectedItemIndex"];
}

Just tried it and it works like a charm. Best,

Flo

guitarflow
  • 2,930
  • 25
  • 38
  • It is not working at the moment it is suggesting that the dot in _self.popupbutton_ should be changed to -> which isnt working... – Rstew Aug 04 '13 at 16:38
  • I think you should definitely read a book on Objective-C before getting serious! I will add more info to the post. – guitarflow Aug 04 '13 at 19:34
  • I still seem to be having a problem, are there any boxes to be unchecked on the popupbutton in the inspector perhaps? – Rstew Aug 11 '13 at 03:05
  • Let me see if I still have the demo project. I can send you that so you can see by yourself what's going on. – guitarflow Aug 11 '13 at 10:20
  • There you go. Let me know when you downloaded the project! https://www.dropbox.com/s/tak7czd7tv1s39l/Popup%20Button.zip – guitarflow Aug 11 '13 at 12:25
  • I downloaded it onto a flash drive from my PS3, I'll test it tomorrow, thanks very much! – Rstew Aug 12 '13 at 02:05