很抱歉一直有问题,但在我的应用程序中,您可以通过另一个页面(设置页面)上的 UISwitchs 切换 3 个 UILabel 和 1 个 UIImageview 的隐藏属性是 YES 还是 NO。奇怪的是,其中一个 UILabel 是隐藏的,即使它被声明为不被隐藏。这是我在设置页面上的代码。
- (IBAction)changeswitch1 {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (artworkswitch.on)
[prefs setInteger:1 forKey:@"AWKey"];
else
[prefs setInteger:0 forKey:@"AWKey"];
}
- (IBAction)changeswitch2 {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (titleswitch.on)
[prefs setInteger:1 forKey:@"TKey"];
else
[prefs setInteger:0 forKey:@"TKey"];
}
- (IBAction)changeswitch3 {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (artistswitch.on)
[prefs setInteger:1 forKey:@"AKey"];
else
[prefs setInteger:0 forKey:@"AKey"];
}
- (IBAction)changeswitch4 {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (volumeswitch.on)
[prefs setInteger:1 forKey:@"VKey"];
else
[prefs setInteger:0 forKey:@"VKey"];
}
所有这些都设置为 IB 中 4 个开关的“值更改”操作。
这是主页的代码
if ([prefs integerForKey:@"AWKey"] == 1)
currentArtwork.hidden = NO;
else if ([prefs integerForKey:@"AWKey"] == 0)
currentArtwork.hidden = YES;
if ([prefs integerForKey:@"TKey"] == 1)
currentSong.hidden = NO;
else if ([prefs integerForKey:@"TKey"] == 0)
currentSong.hidden = YES;
if ([prefs integerForKey:@"AKey"] == 1)
currentArtist.hidden = NO;
else if ([prefs integerForKey:@"AKey"] == 0)
currentArtist.hidden = YES;
if ([prefs integerForKey:@"VKey"] == 1)
volumeview.hidden = NO;
else if ([prefs integerForKey:@"VKey"] == 0)
volumeview.hidden = YES;