开发者

Making an in-app settings page (iPhone)

I am making an app which needs a settings page. Which will be a different class, so how do I pass data from one class to the other? For example: There is a UISwitch on the settings page, and I need to see what option the user selected for anothe开发者_如何学Pythonr class.

Thanks.


On your settings page, use the following code to synchronize your settings -

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

And to get the value of the setting in your other controllers, use the following -

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

Hope this helps you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜