2011-12-03 34 views
2

可能重复:
Is there anyway to set values in the settings.bundle from within the APPiPhone - 更改应用程序设置编程

我开发一个iPhone应用程序,会在某个时刻向用户提示提醒他们设置关闭。从那里他们可以选择启用并继续。我能够获取设置并在我的代码中使用,问题是以编程方式更改它们。下面是我有

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if(buttonIndex == 1){ 

     // Get the application defaults 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
     NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"YES" forKey:@"enabledAutoCheck"]; 

     // Set the new settings and save 
     [defaults registerDefaults:appDefaults]; 
     [defaults synchronize]; 
    } 
} 

我正在胡乱猜测(因为我才开始学习Objective-C和iPhone开发2天前!)它有事可做的事实,这是设置默认设置意味着它们仅在没有做出以前的设置时才使用。

这只是缺少一点点东西,或者是有另一种方法来改变最初设置后的设置吗?

感谢

回答

4

NSUserDefaults是有点误导的名字 - 他们是实际的设置,而不是默认值。

您不需要registerDefaults - 您可以调用[defaults setObject:@"YES" forKey:@"enabledAutoCheck"];(存储设置),然后[defaults synchronize];(保存设置)。这样你可以避免擦除你不想擦除的设置。

你的其他代码没问题。但是,确保将它们实际加载到需要它们的位置,并确保在更改UI设置时更改受影响的UI部件。他们不会更新自己,你知道:-)

+0

非常感谢你!完美的作品:)是的,我知道,我使用InAppSettings工具包,它关注事物的UI侧。 – Peter

相关问题