override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("Selected row \(indexPath.item)")
}
// Override to define the number of sections for the table
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
// Override to define the number of rows in each section
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return shoppingList.count
}
// Override to define the cell for a given row
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
// Configure the cell...
var config = cell.defaultContentConfiguration()
config.text = shoppingList[indexPath.item]
config.image = UIImage(systemName: "applelogo")
config.secondaryText = "Edeka"
cell.contentConfiguration = config
//old way - deprecated
//cell.textLabel?.text = shoppingList[indexPath.item]
return cell
}
The UITableViewCell defines the content of the cells that appear in a UITableView
Inherits from UIView
Has a predefined textLabel, a detailTextLabel and an imageView Property
Has a „Reuse Identifier“ to save resources when rendering
Supports different Cell-Styles