2017-08-02 11 views
0

私は最初のindexPath行のcollectionViewを使用しています。Firebaseから取得した最初のviewControllerのデータの要約を2番目以降から持っています。すべてのラベルを隠して示しましたが、最初のビューとコレクションに戻るreturnViewラベルが消えるラベルがCollectionViewCellから消えます

これは制約があるか、または悪いコードですか?後

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 

    } 

答えて

2

私は制約が正しいと信じて前にあなたは右側に

を消える3つのラベルを見ることができます。 viewControllerトランジション間で変更する必要はありません。ラベルの "textColor"属性に問題がある可能性があります。最初のセルでは、色を白に設定しています。二番目は黒でなければなりません。私は彼らが背景と同じ色だから単純に表示されていないと信じています。 2番目のif文でラベルのtextColorを黒に設定してみてください。

コレクションビューでは再利用可能なセルを使用しているため、ラベルのtextColorがまだ以前から使用されていない可能性があります。

+0

なぜストーリーボードにデフォルトで黒が設定されているのですか? – GaTz

+0

「再利用可能なセル」であるためです。 "collectionView.dequeueReusableCell"を呼び出すと、以前に作成されたセルを取得し、そのセルに新しいデータを設定します。あなたはストーリーボードから作成していません。セルには古いデータがすべて残っています。 (テキストの色などのラベル設定に合わせて) – Jboullianne

+0

あなたはまったく正しいと思います@Jboullianne +1 –

関連する問題