введите описание изображения здесь .
Я пытался сделать приложение погоды.Поэтому, когда пользователь нажимает дату, он должен показывать подробности на другом контроллере.
Вот мой контроллер:
@IBOutlet var tableView: UITableView!
var weatherData = [WeatherModel]()
override func viewDidLoad() {
super.viewDidLoad()
getJSONData {
self.tableView.reloadData()
}
tableView.delegate = self
tableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return weatherData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
for data in weatherData[indexPath.row].list{
cell.textLabel?.text = "Bishkek " + data.dtTxt
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "displayDetails", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? WeatherViewController{
destination.weatherModel = weatherData[(tableView.indexPathForSelectedRow?.row)!]
//I think this is where the error happens.
}
}
func getJSONData(completed: @escaping () -> ()) {
if let filepath = Bundle.main.path(forResource: "weather", ofType: "json") {
do{
let data = try Data(contentsOf: URL(fileURLWithPath: filepath), options: .alwaysMapped)
self.weatherData = try [JSONDecoder().decode(WeatherModel.self, from: data)]
} catch let error{
print(error.localizedDescription)
}
DispatchQueue.main.async {
completed()
}
} else {
print("file not found")
}
}
Описание ошибки:
Завершениеприложение из-за необработанного исключения «NSInternalInconsistencyException», причина: '- экземплярный экземпляр контроллера представления [UITableViewController loadView] с идентификатором «UIViewController-jT8-HX-aGV» из раскадровки «Main», но не получил UITableView.'