Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone-以编程方式更改应用程序设置_Iphone_Ios_Cocoa Touch_Cocoa - Fatal编程技术网

iPhone-以编程方式更改应用程序设置

iPhone-以编程方式更改应用程序设置,iphone,ios,cocoa-touch,cocoa,Iphone,Ios,Cocoa Touch,Cocoa,可能重复: 我正在开发一款iPhone应用程序,它会在某个时候提示用户某个设置已关闭。从那里,他们可以选择启用它并继续。我能够获得设置并在代码中使用,问题是以编程方式更改它们。这是我的 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if(buttonIndex == 1){ // Get the application defaults

可能重复:

我正在开发一款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开发!),这与设置默认设置有关,这意味着只有在之前没有设置的情况下才会使用默认设置

这只是缺少一点东西,还是有其他方法可以在初始设置后更改设置


谢谢

NSUserDefaults
是一个有点误导性的名称-它们是实际设置,而不是默认设置

您不需要
注册表默认值
-相反,您可以调用
[默认设置对象:@“YES”forKey:@“enabledAutoCheck”](存储设置),然后
[默认同步](保存设置)。这样可以避免擦除不想擦除的设置


代码的其余部分很好。但是,请确保在需要的地方实际加载它们,并确保在更改UI设置时更改受影响的UI部分。他们不会更新自己,你知道:-)

非常感谢!工作完美:)是的,我知道,我正在使用InAppSettings工具包,它负责处理UI方面的事情。