I can't figure out how to solve the error: Value of type 'UITableViewCell' has no member 'nameLabel'
The line that throws this error in the code below is: cell.nameLabel.text = item.name, which is at the bottom just above the return cell line.
This may or may not be useful to know, but this is a lesson in a Sololearn course for Swift.
import UIKit
class ItemTableViewController: UITableViewController {
var items = [Item]()
func loadSampleItems() {
items += [Item(name: "item1"), Item(name:
"item2"), Item(name: "item3")]
}
override func viewDidLoad() {
super.viewDidLoad()
loadSampleItems()
}
override func numberOfSections(in tableView:
UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
return items.count
}
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell =
tableView.dequeueReusableCell(withIdentifier:
"ItemTableViewCell", for: indexPath)
let item = items[indexPath.row]
cell.nameLabel.text = item.name
return cell
}