Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.