0

我不明白为什么我保存的首选项在初始化时没有显示在我的设置窗口中。

我将设置保存在 .plist 文件中并applicationDidFinishLaunching像这样加载它们:

// AppDelegate.m

- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
    if (!self.settingsWindow) {
        self.settingsWindow = [[SettingsWindowController alloc] initWithWindowNibName:@"SettingsWindow"];
    }

    [[Settings sharedSettings] load_settings]; // My Singleton Class where I store Settings

    [self loadup_settings]; // Here I load up the settings, saved somwhere in a property list file.

}

- (void) loadup_settings
{

    field_username.stringValue = [[Settings sharedSettings] username];
    field_password.stringValue = [[Settings sharedSettings] password];
    server_id.title = [[Settings sharedSettings] server_id];
    server_language.title = [[Settings sharedSettings] server_language];

    // here I set the stringValue of the fieldUserAgent. But now when I want to
    // show the window, the stringValue is empty. Why is that?
    self.settingsWindow.fieldUserAgent.stringValue = [[Settings sharedSettings] user_agent];

}

- (IBAction) openSettingsWindow:(id)sender
{
    // show settings window on button click. but fieldUserAgent is empty :(
    [self.settingsWindow showWindow:self];

}
4

1 回答 1

0

试试这样: -

在你的 SettingsWindowController.m 类里面 - (void)windowDidLoad 方法设置值: -

- (void)windowDidLoad
{
    self.userAgent.stringValue=[[Settings sharedSettings] user_agent];
    [super windowDidLoad];

// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
于 2013-09-16T15:58:34.803 回答