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!
精彩评论