Created
June 5, 2015 07:53
-
-
Save luckyduck/8101138da237d42fb9b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, UITableViewDataSource, NewtodoViewControllerDelegate { | |
@IBOutlet weak var tableView: UITableView! | |
var todos: [String] = ["Login umsetzen", "Debugging"] { | |
didSet { | |
self.tableView.reloadData() | |
} | |
} | |
// | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "todoCell") | |
} | |
// | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return todos.count | |
} | |
// | |
func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
return 1 | |
} | |
// | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCellWithIdentifier("todoCell", forIndexPath: indexPath) as! UITableViewCell | |
cell.textLabel?.text = todos[indexPath.row] | |
return cell | |
} | |
// | |
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | |
if segue.identifier == "addTodo" { | |
let vc = segue.destinationViewController as! NewtodoViewController | |
vc.todoViewControllerDelegate = self | |
} | |
} | |
// | |
func addedItem(controller: NewtodoViewController, text: String) { | |
self.todos += [text] | |
controller.navigationController?.popViewControllerAnimated(true) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment