我想在我的应用程序的第一个屏幕上进行设置切换。
在我的主视图(显示应用程序加载时间的第一个视图)上,我有一张桌子。每个单元格加载不同的视图。
我想在我的主视图上进行切换,这将改变其他视图的显示方式(具体的文本颜色和背景图像)。
如何才能做到这一点?
我会推荐使用 NSUserDefaults。这是用户更改设置时应激活的代码。
[[NSUserDefaults standardUserDefaults] setBOOL:YES forKey@"Whatever"];
然后,在新屏幕的 viewDidLoad 部分,粘贴以下内容:
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"Whatever"] == YES)
{
//Then do your settings here, for example if whatever toggles the color
//then type: view.backgroundColor = [[UIColor redColor];
}
Obviously there are better ways than to use a bool to store info with NSUserDefaults. I would actually read Apple's documentation for this one. It's interesting and makes sense.
Apple 有一些很棒的应用程序偏好文档:
这是一个很棒的库,它也为您简化了一些事情: