Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import UIKit
  2. import Foundation
  3.  
  4. class TodoTableViewController: UITableViewController {
  5.  
  6. struct Todo {
  7. let description : String
  8. var isDone : Bool = false
  9. init(description:String) {
  10. self.description = description
  11. }
  12. }
  13.  
  14. var todoList = [Todo]()
  15. var doneList = [Todo]()
  16.  
  17. // 중략
  18.  
  19. override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  20. if( isHeaderSection(section)) {
  21. return 1
  22. }
  23. else if( section==1 ) {
  24. return todoList.count
  25. }
  26. return doneList.count
  27. }
  28.  
  29. // 중략
  30.  
  31. private func getTodo(rowAtIndexPath indexPath:NSIndexPath)->Todo {
  32. if( indexPath.section==1 ) {
  33. return todoList[indexPath.row]
  34. }
  35.  
  36. return doneList[indexPath.row]
  37. }
  38. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  39.  
  40. let cell = getCell(tableView, rowAtIndexPath: indexPath)
  41.  
  42. if let todoOrDonCell = cell as? TodoOrDoneTableViewCell {
  43. if( indexPath.section==0 ) {
  44. todoOrDonCell.todoOrDoneLabel.text = "ToDo"
  45. }
  46. else if( indexPath.section==2 ) {
  47. todoOrDonCell.todoOrDoneLabel.text = "Done"
  48. }
  49. }
  50. else if let todoCell = cell as? TodoTableViewCell {
  51. let todo = getTodo(rowAtIndexPath: indexPath)
  52. todoCell.todoLabel.text = todo.description
  53. }
  54.  
  55. return cell
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement