func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return staedte.count } // SelectecIndexChanged func tableView(_: UITableView, didSelectRowAt: IndexPath) { bnChange.isEnabled=true let row = (didSelectRowAt as NSIndexPath).row labelRow.text="row: "+String(row) if let indexPath = tableview.indexPathForSelectedRow { let stadt:Stadt = staedte[(indexPath as NSIndexPath).row] labelInfo.text=stadt.name } } // SelectecIndexChanged func getKontinentText(_ kontinent:Continent) -> String { switch (kontinent) { case Continent.AFRIKA: return "Afrika" case Continent.AMERIKA: return "Amerika" case Continent.ASIEN: return "Asien" case Continent.AUSTRALIA: return "Australien" case Continent.EUROPA: return "Europa" default: return "Afrika" } } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return "Liste" } // UITableViewCellStyle.default: Bild links, Titel rechts // UITableViewCellStyle.subtitle: Bild links, Titel rechts, darunter Zusatzinformation // UITableViewCellStyle.value1: Bild links, Titel in der Mitte, rechts Zusatzinformation // UITableViewCellStyle.value2: Zusatzinformation links, rechts Titel // text, detailTextLabel, imageView func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCell(withIdentifier: "cell") if cell == nil { cell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "cell") } let row = (indexPath as NSIndexPath).row let stadt:Stadt = staedte[ row ] cell?.textLabel!.text = stadt.name cell?.detailTextLabel!.text=stadt.bemerkung switch (stadt.kontinent) { case Continent.AFRIKA: cell?.imageView!.image = UIImage(named: "schwarz") case Continent.AMERIKA: cell?.imageView!.image = UIImage(named: "rot") case Continent.ASIEN: cell?.imageView!.image = UIImage(named: "gelb") case Continent.AUSTRALIA: cell?.imageView!.image = UIImage(named: "gruen") case Continent.EUROPA: cell?.imageView!.image = UIImage(named: "blau") default: cell?.imageView!.image = UIImage(named: "schwarz") } return cell! } override func viewDidLoad() { super.viewDidLoad() let b=false staedte = staedteDB.loadStaedte(db: b) tableview.delegate = self tableview.dataSource = self }