gpt4 book ai didi

ios - 标签从 CollectionViewCell 中消失

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

我使用的是 collectionView,在第一个 indexPath 行中,我有从 Firebase 检索到的第一个 viewController 的数据摘要,从第二个开始,我隐藏了所有标签并显示了其他标签,但是当我返回到第一个 View 并返回时进入collectionView标签消失

是约束问题还是我的代码不好?可以看到右边3个标签消失了

之前:

First

之后:

Second

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cella = collectionView.dequeueReusableCell(
withReuseIdentifier: "cella", for: indexPath) as! ChatViewCell
cella.LabelEur.text = ""
if (indexPath.row == 0){
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: UICollectionViewScrollPosition.centeredHorizontally)
cella.layer.backgroundColor = UIColor("#FFA000").cgColor

cella.Label1.textColor = .white
cella.LabelR.textColor = .white
cella.Date.textColor = .white
cella.Time.textColor = .white
cella.City.textColor = .white

let user = Chat[indexPath.row]
cella.Label1.text = user.sender
cella.LabelEur.isHidden = true
cella.euro.isHidden = true
cella.Tipo.isHidden = false
cella.Quantita.isHidden = false
cella.Misure.isHidden = false
cella.TIpo2.isHidden = false
cella.Label1.isHidden = false
cella.labeldata.isHidden = true
cella.labelora.isHidden = true
cella.Date.text = user.date
cella.Time.text = user.time

if user.caricoc == "1" {
cella.CaricoC.isHidden = false
} else { cella.CaricoC.isHidden = true }
if user.runflat == "1" {
cella.RunFlat.isHidden = false
} else { cella.RunFlat.isHidden = true }
if user.rinforzato == "1" {
cella.Rinforzato.isHidden = false
} else { cella.Rinforzato.isHidden = true }
cella.montaggio.isHidden = true
cella.oraMontaggio.isHidden = true
cella.Distanza.isHidden = true
cella.categoria.isHidden = false
cella.categoria.text = user.cat
cella.TIpo2.text = user.tipo
cella.Misure.text = user.model
cella.Tipo.text = user.marca
cella.Quantita.text = user.numero
cella.LabelR.text = "Ha inserito una richiesta"
//key2 = user.key
misure1 = user.model
caricC = user.caricoc
rnf = user.runflat
rinf = user.rinforzato
tipo = user.tipo
marca = user.marca
quantita = user.numero
cat = user.cat
//last = user.lastname
lat = user.lat
lng = user.lng
}else{

}
if (indexPath.row >= 1){
let user = Chat[indexPath.row]
cella.Label1.text = ""
cella.Date.text = user.date
cella.Time.text = user.time
cella.RunFlat.isHidden = true
cella.Rinforzato.isHidden = true
cella.CaricoC.isHidden = true
cella.LabelEur.isHidden = false
cella.categoria.isHidden = true
cella.euro.isHidden = false
cella.TIpo2.isHidden = true
cella.Tipo.isHidden = true
cella.Quantita.isHidden = true
cella.labelora.isHidden = false
cella.labeldata.isHidden = false
cella.montaggio.isHidden = false
cella.oraMontaggio.isHidden = false
cella.Distanza.isHidden = false
cella.oraMontaggio.text = user.oraApp
cella.montaggio.text = user.dataApp
cella.Misure.isHidden = true

let prezzo: Float = (Float(user.text)?.multiplied(by: 1.10))!
let nenno: Float = 3.234
let prezzo2 = String(describing: NSDecimalNumber(string: String(format:"%.0f", prezzo)))
cella.LabelEur.text = prezzo2
cella.LabelR.isHidden = true
cella.layer.backgroundColor = UIColor("#FFFFFF").cgColor
let posInt = Int(user.positiondef)
if (posInt! <= 5) {
cella.Distanza.text = "A meno di 5km"
} else if (posInt! <= 10) {
cella.Distanza.text = "A meno di 10km"
} else if (posInt! <= 15) {
cella.Distanza.text = "A meno di 15 km"
}
/*
if (user.positiondef != nil) {
if (user.positiondef.hasPrefix("0")) {
cella.Distanza.text = "Nelle vicinanze"
} else {
cella.Distanza.text = user.positiondef+"KM"
}
}*/
cella.City?.text = user.city
self.Chat = self.Chat.sorted{ $0.text.compare($1.text, options: .numeric) == ComparisonResult.orderedAscending }

}

return cella

}

最佳答案

我相信约束是正确的。它们不应该在 viewController 转换之间改变。问题可能出在标签的“textColor”属性上。在第一个单元格中,您将颜色设置为白色。在第二个中,它们应该是黑色的。我相信它们的显示不仅仅是因为它们与背景颜色相同。尝试在第二个“if”语句中将标签的 textColor 设置为黑色。

if indexPath.row >= 1 {
//set textColor of labels here.
}

Collection Views 使用可重复使用的单元格,因此标签的 textColor 可能仍然是白色的,因为之前使用过。

关于ios - 标签从 CollectionViewCell 中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45463795/

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