2013-09-16 25 views
0

我不明白爲什麼在初始化時我的保存的首選項未顯示在我的設置窗口中。在初始化時,NSTextField上的保存的首選項未設置

我在的.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]; 

} 

回答

0

嘗試這樣的: -

在你SettingsWindowController.m類中 - (空) 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. 
} 
+0

確定這個工程,但stringValue的是'null'直到我點擊'openSettingsWindow',這裏則stringValue的獲取設置。初始化時沒有辦法設置它嗎? –

+0

但是你只想在顯示窗口後顯示數據,所以這將是更好的方法 –

相關問題