我不明白为什么我保存的首选项在初始化时没有显示在我的设置窗口中。
我将设置保存在 .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];
}