|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UITableViewDelegate, UITableViewDataSource
override func viewDidLoad() {
tableview.delegate=self
tableview.dataSource=self
}
|
|
|
|
|
|
|
|
|
|
|
|
Anzahl der Gruppen
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
Set the spacing between sections
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50 // cellSpacingHeight
}
|
|
|
|
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cities.count
}
|
|
|
|
|
|
|
|
|
|
|
|
func tableView(_: UITableView, didSelectRowAt: IndexPath) {
let row = (didSelectRowAt as NSIndexPath).row
// Aktion
}
|
|
|
|
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch (indexPath.row) {
case 0:
return 100
case 3:
return 80
default:
return UITableView.automaticDimension
} // switch
}
|
|
|
|
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "reuseIdentifier")
/* Typen
UITableViewCellStyle.default Bild links, Titel rechts
UITableViewCellStyle.value1 Titel in der Mitte, rechts Zusatzinformation
UITableViewCellStyle.value2 Zusatzinformation links, rechts Titel
UITableViewCellStyle.subtitle Bild links, Titel rechts, darunter Zusatzinformation
*/
let row = (indexPath as NSIndexPath).row
let city:City = cities[ row ]
cell.textLabel?.text = city.name
cell.detailTextLabel?.text = city.remark
switch city.continent {
case Continent.AFRICA:
cell.imageView?.image = UIImage(named: "schwarz")
case Continent.AMERICA:
cell.imageView?.image = UIImage(named: "rot")
default:
cell.imageView?.image = UIImage(named: "default")
}
return cell
}
|
|
|
|
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "mycell", for: indexPath) as! MyCell
let row = (indexPath as NSIndexPath).row
print("row:"+String(row))
let city:City = cities[ row ]
cell.title?.text = city.name
cell.subtitle?.text = city.remark
switch city.continent {
case Continent.AFRICA:
cell.imgContinent?.image = UIImage(named: "schwarz")
case Continent.AMERICA:
cell.imgContinent?.image = UIImage(named: "rot")
default:
cell.imgContinent?.image = UIImage(named: "default")
}
return cell
}
|
|
|
|
|
|
|
|
|
|
|
|
textcolor
cell.subtitle?.textColor = UIColor(named: "redColor")
backgroundColor
cell.backgroundColor = UIColor(named: "lightyellowColor")
borderWidth
cell.layer.borderWidth = 3
borderColor
cell.layer.borderColor = UIColor.blue.cgColor
borderRadius
cell.layer.cornerRadius = 25
Shadow of the cell
cell.subtitle?.shadowColor = UIColor(named: "redColor")
cell.layer.shadowColor = UIColor.orange.cgColor
|
|
|
Segue
|
|
|