0

我已经尝试了很多东西,但无法让它发挥作用......

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

不工作,有什么建议吗?

4

1 回答 1

3

这是我刚刚创建的一个最小示例:

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"];
}

刚试了一下,它就像一个魅力。最好的,

弗洛

于 2013-08-04T12:09:29.753 回答