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
}
私は、シミュレータの画面と私のストーリーボードのスクリーンショットを追加しました。助けてくれてありがとう。
How I use CollectionViewCell in View
この時点で、シミュレータに移動します。デバッグ - >ビューデバッグ - >キャプチャビューのヒイラキーを表示します。これはあなたの意見で何が起こっているかについて多くの情報を提供します。 –
私はセルを見ることができません、ただUIImageView。ありがとうございました! – slytrkmn
私はそれを修正しました。本当に本当にありがとう! @ AndrewMcKinley – slytrkmn