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