2016-12-08 16 views
0

CollectionViewCellに2つのラベルと1つの画像ビューがあります。私はセル内にイメージを設定できますが、セルにラベルを設定することはできません。 CollectionViewCellクラス:私は私のビューコントローラでそれを使用する方法CollectionViewCellのラベルが表示されない

class CollectionViewCell: UICollectionViewCell { 

    @IBOutlet weak var weatherIcon: UIImageView! 
    @IBOutlet weak var degreeLbl: UILabel! 
    @IBOutlet weak var dateTimeLbl: UILabel! 

    override func awakeFromNib() { 
     super.awakeFromNib() 
    } 
} 

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return self.fiveDaysWeather.count 
} 

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCell(
     withReuseIdentifier: "collectionViewCell", for: indexPath) as! CollectionViewCell 


    if fiveDaysWeather.count > 0{ 
     let forecast = fiveDaysWeather[indexPath.row] 
     let icon = forecast.icon! 
     if let url = URL(string: "http://openweathermap.org/img/w/\(icon).png"){ 
      if let data = try? Data(contentsOf: url) { 
       cell.weatherIcon.image = UIImage(data:data)! 
      } 
     } 

     cell.dateTimeLbl?.text = forecast.hour! 
     cell.degreeLbl?.text = "\(forecast.tempMax!)°" 
    } 
    return cell 

} 

私は、シミュレータの画面と私のストーリーボードのスクリーンショットを追加しました。助けてくれてありがとう。

Simulator Response

How I use CollectionViewCell in View

+1

この時点で、シミュレータに移動します。デバッグ - >ビューデバッグ - >キャプチャビューのヒイラキーを表示します。これはあなたの意見で何が起こっているかについて多くの情報を提供します。 –

+0

私はセルを見ることができません、ただUIImageView。ありがとうございました! – slytrkmn

+0

私はそれを修正しました。本当に本当にありがとう! @ AndrewMcKinley – slytrkmn

答えて

0

たぶん、あなたは、クラスを登録する必要があります。 CollectionViewControllerクラスのviewDidLoadメソッドでこれを試してください。

self.collectionView.registerClass(CollectionViewCell.self, forCellReuseIdentifier: "collectionViewCell") 

また、弱い変数が存在するかどうかを確認する必要があります。このコード行にブレークポイントを置き、ラベル/その他の項目を検査してください。

cell.dateTimeLbl?.text = forecast.hour! 
関連する問題