Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  4.  
  5. @IBOutlet weak var tableView: UITableView!
  6.  
  7. var itemsArray: [ToDoItem] = []
  8.  
  9. func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  10. return itemsArray.count
  11. }
  12.  
  13. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  14. let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell!
  15.  
  16. let tempItem = itemsArray[indexPath.row]
  17.  
  18. cell.textLabel?.text = tempItem.itemName
  19.  
  20. return cell!
  21. }
  22.  
  23.  
  24. override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  25. if segue.identifier == "detailsegue" {
  26. let destVC = segue.destinationViewController as! DetailViewController
  27.  
  28. let selectedIndex = tableView.indexPathForSelectedRow
  29.  
  30. destVC.myItem = itemsArray[selectedIndex!.row] as? ToDoItem
  31. }
  32. }
  33.  
  34.  
  35. override func viewDidLoad() {
  36. super.viewDidLoad()
  37. let item1 = ToDoItem(name: "Eat", desc: "Eat until i am full. I prefer local food though!", place: "Food Court")
  38. itemsArray.append(item1)
  39.  
  40. let item2 = ToDoItem(name: "Drink", desc: "Drink until i am full. I prefer local drink though!", place: "Drink Court")
  41. itemsArray.append(item2)
  42.  
  43. let item3 = ToDoItem(name: "Jump", desc: "Jump until i am tired. I prefer local jump though!", place: "Sport Center")
  44. itemsArray.append(item3)
  45. // Do any additional setup after loading the view, typically from a nib.
  46. }
  47.  
  48. override func didReceiveMemoryWarning() {
  49. super.didReceiveMemoryWarning()
  50. // Dispose of any resources that can be recreated.
  51. }
  52. }
  53.  
  54. init(name: String, desc: String?, place:String?) {
  55. self.itemName = name
  56. self.itemDescription = desc
  57. self.itemPlace = place
  58. self.completed = false
  59. }
  60.  
  61. import UIKit
  62.  
  63. class DetailViewController: UIViewController {
  64.  
  65. var myItem: ToDoItem?
  66.  
  67.  
  68. @IBOutlet weak var nameLabel: UILabel!
  69. @IBOutlet weak var placeLabel: UILabel!
  70. @IBOutlet weak var descLabel: UILabel!
  71.  
  72. override func viewDidLoad() {
  73. super.viewDidLoad()
  74.  
  75. nameLabel.text = myItem?.itemName
  76. placeLabel.text = myItem?.itemDescription
  77. // Do any additional setup after loading the view.
  78. }
  79.  
  80. override func didReceiveMemoryWarning() {
  81. super.didReceiveMemoryWarning()
  82. // Dispose of any resources that can be recreated.
  83. }
  84.  
  85.  
  86. /*
  87. // MARK: - Navigation
  88.  
  89. // In a storyboard-based application, you will often want to do a little preparation before navigation
  90. override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  91. // Get the new view controller using segue.destinationViewController.
  92. // Pass the selected object to the new view controller.
  93. }
  94. */
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement