Showing property in tablecell

I am following a course and am trying so test myself.
I have a model and I give values to properties from a json-file.
(If Im showing code wrong please tell me how I shoud do it)


This works:

func updateUIWithWeatherData() {

cityLabel.text = weatherDataModel.city

temperatureLabel.text = String(weatherDataModel.temperature)

weatherIcon.image = UIImage(named: weatherDataModel.weatherIconName)

}


But here it doesn't. Test shows but not the city.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")

cell.textLabel?.text = weatherDataModel.city

//cell.textLabel?.text = "test"

return cell

}

Accepted Reply

But I can show a value set in


That has nothing to do with IBOutlet connection.


You need to open the storyboard editor and connect your Table View in design canvas to the IBOutlet `tableView` in the code.

Replies

When you look at the code, you have a white circle on the left of

@IBOutlet weak var tableView: UITableView!


If the circle is empty, you are not connected.

If black you are connected to something. If you hover the mouse over the dot, whist having the storyboards opened in other pane, you should see the tableView being hilited.


If not:

- drag from the circle to the tableView in storyboard

- release when tableView gets hilited.

It worked!


Thank you both!
I'm sorry that I couldn't mark both as correct answers.
Clearly I have to learn more about the basics.
One question: Could I have made this connection completely in code?


Question two: I want to display two values in one cell. The staition from the API on the left and the time on the right.


Without explaining everything, could you give me a hint to the right solution?