Freaky UISwitch/UILabel.hidden/UIImageView.hidden Problem!
Sorry for the constant questions, but in my app, you are able to toggle if 3 UILabels and 1 UIImageview's hidden property is YES or NO via UISwitchs on another page (The settings page). The weird part is, one of the UILabels is hidden, even when it is declared that it is not to be hidden. Here is my code on the settings page.
- (IBAction)changeswitch1 {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]开发者_如何学Go;
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"];
}
All of this is set as the 'value changed' action in IB for the 4 switches.
Here is the code for the main page
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;
This is just a guess, since I don't know the res of the code. But maybe it is hidden because another UILabel is positioned infront of it?. You can try:
[self.view bringSubviewToFront:yourLabel];
-Oscar
My solution was to have the label/imageview's hidden property set to NO upon the first launch.
精彩评论