gpt4 book ai didi

ios - 如何隐藏标签?

转载 作者:可可西里 更新时间:2023-11-01 01:33:13 24 4
gpt4 key购买 nike

如您所见,我这里有一个收藏 View 列表,有些产品有促销价,有些则没有。对于有促销的产品,它会显示红色价格和实际价格(旁边)。现在的问题是,我使用 segue 从以前的 View 中传递了所有这些值,现在我必须为那些没有促销价的产品隐藏促销价标签,我应该怎么做?

hide label

代码如下:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! SubCategoryDetailsCollectionViewCell

let grey = UIColor(red: 85.0/255.0, green: 85.0/255.0, blue: 85.0/255.0, alpha: 1.0)
cell.layer.borderWidth = 1.0
cell.layer.borderColor = grey.CGColor

cell.titleLabel.text = name[indexPath.row]
cell.imageView.sd_setImageWithURL(NSURL(string: thumbImg1[indexPath.row] ))

我尝试用这种方式隐藏标签,但它并没有真正起作用,它工作了一段时间,在我开始滚动我的收藏 View 后,所有促销标签都被隐藏了

    if promo[indexPath.row] == "0"{

cell.promoLabel.hidden = true
}else{
cell.promoLabel.text = "RM" + promo[indexPath.row]
}

cell.priceLabel.text = "RM" + price[indexPath.row]

cell.productLabel.text = label[indexPath.row]

cell.setNeedsDisplay()
return cell
}

最佳答案

试试这个

if promo[indexPath.row] == "0"{
cell.promoLabel.hidden = true
}else{
cell.promoLabel.hidden = false
cell.promoLabel.text = "RM" + promo[indexPath.row]
}


cell.productLabel.text = label[indexPath.row]

cell.setNeedsDisplay()
return cell

关于ios - 如何隐藏标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38847019/

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