Не вижу никаких данных в ячейке представления UICollection - PullRequest
0 голосов
/ 16 марта 2020

. enter image description here

Должна быть почасовая погода в collectionView, которая находится под температурной меткой. Источник данных и делегирование ViewController завершены. Никаких ошибок и никакого кода об информации о ячейке в терминале при запуске кода на симуляторе. Я буду рад любой помощи.

import UIKit

class HourlyWeatherViewCell: UICollectionViewCell {


@IBOutlet weak var hourLabel: UILabel!
@IBOutlet weak var weatherOnHourLabel: UILabel!
@IBOutlet weak var tempOnHourLabel: UILabel!

}

ViewController.swift Я получаю информацию по darkskyapi.

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate, UITableViewDataSource,     UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate {

@IBOutlet weak var hourlyWeatherCollectionView: UICollectionView!

override func viewDidLoad() {
    super.viewDidLoad()
    requestLocationPermission()
    hourlyWeatherCollectionView.dataSource = self
    hourlyWeatherCollectionView.delegate = self
    self.hourlyWeatherCollectionView.reloadData()
}
func currentWeatherRequest() {
    let session = URLSession.shared
    let weatherURL = URL(string: "https://api.darksky.net/forecast/key/\(lat),\(lon)?lang=ru&unit=si" )!
    print(weatherURL)
    let dataTask = session.dataTask(with: weatherURL) { (data: Data?,response: URLResponse?,error: Error?) in
        if let error = error {
            print("Error:\n\(error)")

        } else {
            if let jsonData = data {

                do {
                    let dataString = String(data: jsonData, encoding: String.Encoding.utf8)
          print("\(dataString!)")
                let decoder = JSONDecoder()
                    self.responseModel = try decoder.decode(WeatherForecast.self, from: jsonData)

                    DispatchQueue.main.async {
                        self.cityNowNameLabel.text = self.responseModel?.timezone
                        self.weatherNowLabel.text =  (self.responseModel?.currently.summary).map { $0.rawValue }
                        self.weatherNowdescriptionLabel.text = (self.responseModel?.currently.icon).map { $0.rawValue }
                        self.weatherFiveDaysTableView.reloadData()
                        self.hourlyWeatherCollectionView.reloadData()
                        self.reloadView()

                    }

                } catch let error {
                  print("Error: \(error)")
                }
            }else {
            print("Error: did not receive data")

        }
        }
    }
    dataTask.resume()

}
public func numberOfSections(in collectionView: UICollectionView) -> Int {
    1
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
       return responseModel?.hourly.data[0...24].count ?? 25
   }
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
       guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HourlyWeather", for: indexPath) as? HourlyWeatherViewCell else {return UICollectionViewCell()}

       let dateList = responseModel?.hourly
       if let nowDate = dateList?.data[indexPath.row].time{
           let dateFormatter = DateFormatter()
           let date = Date(timeIntervalSince1970: (TimeInterval(nowDate)))
           dateFormatter.locale = Locale(identifier: "en_US")
           dateFormatter.setLocalizedDateFormatFromTemplate("HH")
           if indexPath.row == 0 {
            cell.hourLabel.text = "Now"
           }
           cell.hourLabel.text = dateFormatter.string(from: date)
           print(dateFormatter.string(from: date))
       } else {
           cell.hourLabel.text = "No data"
       }

       cell.weatherOnHourLabel.text = String(describing: dateList?.icon)
       print(String(describing: dateList?.icon))
       cell.tempOnHourLabel.text = String(describing: dateList?.data[indexPath.row].temperature)
       print(String(describing: dateList?.data[indexPath.row].temperature))
           return cell
   }
...