奇怪的 UISwitch/UILabel.hidden/UIImageView.hidden 问题!

发布于 2024-08-22 03:20:20 字数 1834 浏览 9 评论 0原文

很抱歉一直有问题,但在我的应用程序中,您可以通过另一个页面(设置页面)上的 UISwitch 来切换 3 个 UILabels 和 1 个 UIImageview 的隐藏属性是“是”还是“否”。奇怪的是,其中一个 UILabels 被隐藏,即使它声明不被隐藏。这是我在设置页面上的代码。


- (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"];
}
All of this is set as the 'value changed' action in IB for the 4 switches.

这是主页的代码

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;

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];
    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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伤感在游骋 2024-08-29 03:20:20

这只是一个猜测,因为我不知道代码的内容。但也许它被隐藏是因为另一个 UILabel 位于它前面?你可以尝试:

[self.view bringSubviewToFront:yourLabel];

-奥斯卡

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

潇烟暮雨 2024-08-29 03:20:20

我的解决方案是在第一次启动时将标签/图像视图的隐藏属性设置为“否”。

My solution was to have the label/imageview's hidden property set to NO upon the first launch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文