1

我正在制作一个需要设置页面的应用程序。这将是一个不同的类,那么我如何将数据从一个类传递到另一个类?例如:设置页面上有一个UISwitch,我需要查看用户为另一个类选择了什么选项。

谢谢。

4

1 回答 1

3

在您的设置页面上,使用以下代码同步您的设置 -

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: data forKey: @""]; // The forKey is the name of the setting you're going to sync
[defaults synchronize];

要获取其他控制器中设置的值,请​​使用以下命令 -

NSString *settingValue = [[NSUserDefaults standardUserDefaults] objectForKey: @""]; // The objectForKey is the name of the setting you're getting the value for.

希望这对你有帮助!

于 2010-08-18T16:24:18.153 回答