// // ViewController.swift // iOSTableViewOwnNavigator // // Created by Michael Wilhelm on 8/05/2016. // Copyright © 2016 Michael Wilhelm. All rights reserved. // import UIKit class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var staedte = [Stadt]() var neueStadtNr=0 @IBOutlet var tableview: UITableView! @IBOutlet var bnEdit: UIButton! @IBOutlet var bnNew: UIButton! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. staedte.append( Stadt("New York", "Manhattan") ) staedte.append( Stadt("Mailand", "Mailander Scala") ) staedte.append( Stadt("Rom", "Vatikan, Michelangelo") ) staedte.append( Stadt("Moskau", "Roter Platz") ) staedte.append( Stadt("Wernigerode", "HS Harz") ) staedte.append( Stadt("New York", "Manhattan") ) tableview.delegate=self tableview.dataSource=self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return staedte.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell") cell.textLabel!.text = "xx" let stadt:Stadt = staedte[indexPath.row] // as! Stadt cell.textLabel!.text = stadt.name cell.detailTextLabel!.text=stadt.bemerkung // let pictname = "Bild"+String(indexPath.row%5) // let image : UIImage = UIImage(named: pictname)! // cell.imageView!.image = image return cell } @IBAction func bnRemoveActionClick(sender: UIButton) { } @IBAction func unwindToEditView(segue:UIStoryboardSegue) { if let src = segue.sourceViewController as? EditViewController { if let indexPath = tableview.indexPathForSelectedRow { let stadt:Stadt = staedte[indexPath.row] stadt.name = (src.stadt?.name)! stadt.bemerkung = (src.stadt?.bemerkung)! // update tableview.delegate=nil tableview.dataSource=nil tableview.delegate=self tableview.dataSource=self } } } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if let button:UIButton = sender as! UIButton { if button==bnEdit { if let indexPath = tableview.indexPathForSelectedRow { let stadt:Stadt = staedte[indexPath.row] if let dest = segue.destinationViewController as? EditViewController { dest.stadt=stadt } } } } } }