|
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableview: UITableView!
var cities : [City] = []
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.rightBarButtonItem = self.editButtonItem
cities = CitiesDB.loadCitiesIntern()
tableview.delegate=self
tableview.dataSource=self
}
// count of columns
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
// count of rows
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cities.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
//let cell: UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "cell")
let cell: UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "reuseIdentifier")
// Configure the cell...
let row = (indexPath as NSIndexPath).row
let city:City = cities[ row ]
cell.textLabel?.text = city.name
cell.detailTextLabel?.text = city.remark
return cell
}
}
|
|