我希望在 IOS 平台上的 NSUserDefaults
中存储 UIControlState
的多个实例。
假设有一个带有各种 UIControl
元素的首选项面板,例如 UISlider
、UISwitch
等。
目前,我在 viewWillAppear
中有一个 loadPrefs 函数,在 viewWillDisappear
中有一个相应的 writePrefs。
有没有一种简单的方法可以遍历 NSUserDefaults
和相应地设置相关状态?
是否有通过 NSArray
或其他一些集合执行此操作的“正确”方法,或者是否不值得花时间和麻烦?
最佳答案
您可以使用 dictionaryRepresentation 方法将整个 NSUserDefaults 内容作为 NSDictionary 获取:
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
for (NSString *key in [dict allKeys])
{
// do whatever you want
}
希望这对您有所帮助。
关于iphone - 你如何在 NSUserDefaults 中存储多个 UIControlState 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9573334/