Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mriddle committed Apr 27, 2016
1 parent fc9be48 commit 17c28bb
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions Checklists/ChecklistViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,37 @@ class ChecklistViewController: UITableViewController {
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
return items.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ChecklistItem", forIndexPath: indexPath)

let label = cell.viewWithTag(1000) as! UILabel
let item = items[indexPath.row]
label.text = item.text

if indexPath.row < items.count {
label.text = items[indexPath.row].text
}
configureCheckmarkForCell(cell, atIndexPath: indexPath)
configureCheckmarkForCell(cell, item: item)
return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if indexPath.row < items.count {
let item = items[indexPath.row]
item.checked = !item.checked
}
let item = items[indexPath.row]
item.checked = !item.checked

configureCheckmarkForCell(cell, atIndexPath: indexPath)
configureCheckmarkForCell(cell, item: item)
}

tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

func configureCheckmarkForCell(cell: UITableViewCell, atIndexPath: NSIndexPath) {
if atIndexPath.row < items.count {
let item = items[atIndexPath.row]

if item.checked {
cell.accessoryType = .Checkmark
} else {
cell.accessoryType = .None
}
func configureCheckmarkForCell(cell: UITableViewCell, item: ChecklistItem) {
if item.checked {
cell.accessoryType = .Checkmark
} else {
cell.accessoryType = .None
}
}

Expand Down

0 comments on commit 17c28bb

Please sign in to comment.