Skip to content

Instantly share code, notes, and snippets.

@luckyduck
Created June 5, 2015 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckyduck/8101138da237d42fb9b2 to your computer and use it in GitHub Desktop.
Save luckyduck/8101138da237d42fb9b2 to your computer and use it in GitHub Desktop.
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