gpt4 book ai didi

ios - 使用 "isEqualToString"设置标签文本

转载 作者:行者123 更新时间:2023-11-28 19:08:07 25 4
gpt4 key购买 nike

我正在尝试使用 parse.com 上的字符串来设置 UILabel 中的文本。在 Parse 上,我有一个名为“isItemOnSpecial”的字符串列,如果该项目是特殊的,我会将其设置为是。如果字符串设置为是,那么我希望 UILabel 显示 specialPrice 列中的字符串,否则我希望隐藏 UILabel。这是我的代码:

// This is where I am setting up my tableViewCell//

NSString *itemOnSpecial = [object objectForKey:@"isItemOnSpecial"];

if ([itemOnSpecial isEqualToString:@"yes"]) {
UILabel *specialLabel = (UILabel*) [cell viewWithTag:5];
specialLabel.text = [object objectForKey:@"specialPrice"];
} else {
UILabel *specialLabel = (UILabel*) [cell viewWithTag:5];
[specialLabel setHidden:true];
}

当我使用此代码运行应用程序时,UILabel 始终设置为隐藏。任何对此的帮助将不胜感激,它困扰了我很长时间。

感谢您的宝贵时间。

最佳答案

我看到的最紧迫的问题是,您似乎正在将此代码用于 UITableViewCell 或类似的代码,在这种情况下,您需要确保取消隐藏可能已被先前单元格加载隐藏的标签.例如:

NSString *itemOnSpecial = [object objectForKey:@"isItemOnSpecial"];

if ([itemOnSpecial caseInsensitiveCompare:@"yes"] == NSOrderedSame) {
UILabel *specialLabel = (UILabel*) [cell viewWithTag:5];
specialLabel.text = [object objectForKey:@"specialPrice"];
[specialLabel setHidden:NO]; // Notice this line
}else{
UILabel *specialLabel = (UILabel*) [cell viewWithTag:5];
[specialLabel setHidden:YES];
}

关于ios - 使用 "isEqualToString"设置标签文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18443028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com