Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 标签从CollectionViewCell中消失_Ios_Swift_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios 标签从CollectionViewCell中消失

Ios 标签从CollectionViewCell中消失,ios,swift,uicollectionview,uicollectionviewcell,Ios,Swift,Uicollectionview,Uicollectionviewcell,我使用collectionView,在第一行中,我有从Firebase检索到的第一个viewController的数据摘要,从第二行开始,我隐藏了所有标签并显示了其他标签,但当我返回第一个视图并返回collectionView时,标签消失了 这是约束的问题,还是我的代码不好?您可以看到右侧3个标签消失 之前: 之后: func collectionView(collectionView:UICollectionView,cellForItemAt indexPath:indexPath)->

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

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

之前:

之后:

func collectionView(collectionView:UICollectionView,cellForItemAt indexPath:indexPath)->UICollectionViewCell{
设cella=collectionView.dequeueReusableCell(
withReuseIdentifier:“cella”,用于:indexPath)as!ChatViewCell
cella.LabelEur.text=“”
if(indexPath.row==0){
collectionView.selectItem(位于:indexPath,动画:true,scrollPosition:UICollectionViewScrollPosition.Centered水平)
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=真
cella.euro.isHidden=正确
cella.Tipo.isHidden=假
cella.Quantita.isHidden=假
cella.Misure.isHidden=错误
cella.TIpo2.isHidden=false
cella.Label1.isHidden=false
cella.labeldata.isHidden=true
cella.labelora.isHidden=真
cella.Date.text=user.Date
cella.Time.text=user.Time
如果user.caricoc==“1”{
cella.CaricoC.isHidden=false
}else{cella.CaricoC.ishiden=true}
如果user.runflat==“1”{
cella.RunFlat.ishiden=false
}else{cella.RunFlat.ishiden=true}
如果user.rinforzato==“1”{
cella.Rinforzato.isHidden=假
}else{cella.Rinforzato.isHidden=true}
cella.montaggio.isHidden=真
cella.oraMontaggio.isHidden=真
cella.Distanza.isHidden=真
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
液化天然气=用户液化天然气
}否则{
}
如果(indexPath.row>=1){
let user=Chat[indexPath.row]
cella.Label1.text=“”
cella.Date.text=user.Date
cella.Time.text=user.Time
cella.RunFlat.ishiden=true
cella.Rinforzato.isHidden=真
cella.CaricoC.isHidden=真
cella.LabelEur.isHidden=假
cella.categoria.isHidden=真
cella.euro.isHidden=错误
cella.TIpo2.isHidden=true
cella.Tipo.isHidden=真
cella.Quantita.isHidden=真
cella.labelora.isHidden=假
cella.labeldata.isHidden=false
cella.montaggio.isHidden=假
cella.oraMontaggio.isHidden=假
cella.Distanza.isHidden=假
cella.oraMontaggio.text=user.oraApp
cella.montaggio.text=user.dataApp
cella.Misure.isHidden=真
让prezzo:Float=(Float(user.text)?。乘以(1.10))!
设nenno:Float=3.234
设prezzo=String(描述:NSDecimalNumber(String:String(格式:“%.0f”,prezzo)))
cella.LabelEur.text=prezzo2
cella.LabelR.isHidden=真
cella.layer.backgroundColor=UIColor(“#FFFFFF”).cgColor
设posInt=Int(user.positiondef)

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

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

集合视图使用可重复使用的单元格,因此标签的textColor与以前使用的相比可能仍然是白色的。

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

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

集合视图使用可重复使用的单元格,因此标签的文本颜色可能与以前使用的颜色相比仍然是白色。

为什么故事板中的设置默认为黑色?因为它们是“可重复使用的单元格”。当您调用“collectionView.dequeueReusableCell”时您正在获取以前创建的单元格并在其上设置新数据。您不是从情节提要中创建的。该单元格上仍将包含所有旧数据。(以及标签设置,如文本颜色)为什么在情节提要中默认设置为黑色?因为它们是“可重用的单元格”。当您