Guest User

Untitled

a guest
Jan 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. import Foundation
  2.  
  3. @IBOutlet weak var collectionView: UICollectionView!
  4. @IBOutlet weak var continueButton: RoundedButton!
  5. @IBOutlet weak var notSureButton: RoundedButton!
  6. @IBOutlet weak var notSureButtonTop: NSLayoutConstraint!
  7.  
  8. var collectionData = [[String: String]]()
  9.  
  10.  
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. self.appointment = fetchAppointment()
  14. self.collectionView.delegate = self
  15. self.collectionView.dataSource = self
  16. self.collectionData.append([
  17. "image": "regularExam",
  18. "text": "Regular Exam",
  19. "data": "regular_exam"])
  20. self.collectionData.append([
  21. "image": "vaccines",
  22. "text": "Essential Vaccines",
  23. "data": "vaccines"])
  24. self.collectionData.append([
  25. "image": "meds",
  26. "text": "Parasite Meds",
  27. "data": "preventitive_meds"])
  28. self.collectionData.append([
  29. "image": "dog",
  30. "text": "My pet is sick",
  31. "data": "sick_pet"])
  32.  
  33. self.notSureButton.layer.shadowColor = Constants.appColor.gray.light.cgColor
  34. self.notSureButton.layer.shadowOffset = CGSize(width: 0, height: 2.0)
  35. self.notSureButton.layer.shadowRadius = 3.0
  36. self.notSureButton.layer.shadowOpacity = 0.8
  37. self.notSureButton.layer.masksToBounds = false
  38. }
  39.  
  40. override func viewDidLayoutSubviews(){
  41. self.collectionView.frame = CGRect(x: self.collectionView.frame.origin.x, y: self.collectionView.frame.origin.y, width: self.collectionView.frame.size.width, height: CGFloat(2 * 170))
  42. self.notSureButtonTop.constant = CGFloat(2 * 170) + 20.0
  43. self.view.layoutIfNeeded()
  44. self.collectionView.reloadData()
  45. }
  46.  
  47. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  48. return self.collectionData.count
  49. }
  50.  
  51. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  52. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SelectVisitForCollectionViewCell", for: indexPath) as! SelectVisitForCollectionViewCell
  53. let item = indexPath.item
  54.  
  55. cell.displayContent(image: UIImage(named: self.collectionData[item]["image"]!)!, text: self.collectionData[item]["text"]!)
  56.  
  57. return cell
  58. }
  59.  
  60. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  61. if let cell = collectionView.cellForItem(at: indexPath) as? SelectVisitForCollectionViewCell {
  62. var categories = self.appointment?.categories
  63. if let index = categories!.index(of: self.collectionData[indexPath.item]["data"]!) {
  64. categories?.remove(at: index)
  65. cell.showSelected(false)
  66. } else {
  67. categories?.append(self.collectionData[indexPath.item]["data"]!)
  68. cell.showSelected(true)
  69. }
  70.  
  71. self.appointment?.categories = categories!
  72.  
  73. if (self.appointment?.categories.count)! > 0 {
  74. self.continueButton.isHidden = false
  75. } else {
  76. self.continueButton.isHidden = true
  77. }
  78.  
  79. saveAppointment(data: self.appointment!)
  80. }
  81. }
  82.  
  83.  
  84. @IBAction func onNotSureButtonPressed(_ sender: Any) {
  85. var categories = self.appointment?.categories
  86. if let index = categories!.index(of: "not_sure") {
  87. categories?.remove(at: index)
  88. self.notSureButton.backgroundColor = UIColor.white
  89. self.notSureButton.setTitleColor(Constants.appColor.gray.dark, for: .normal)
  90. } else {
  91. categories?.append("not_sure")
  92. self.notSureButton.backgroundColor = Constants.appColor.yellow.main
  93. self.notSureButton.setTitleColor(UIColor.white, for: .normal)
  94. }
  95.  
  96. self.appointment?.categories = categories!
  97.  
  98. if (self.appointment?.categories.count)! > 0 {
  99. self.continueButton.isHidden = false
  100. } else {
  101. self.continueButton.isHidden = true
  102. }
  103. print(self.appointment?.categories)
  104. saveAppointment(data: self.appointment!)
  105. }
  106.  
  107. @IBAction func onContinueButtonPressed(_ sender: Any) {
  108. self.parentPageboy?.scrollToPage(.next, animated: true)
  109. }
Add Comment
Please, Sign In to add comment