Guest User

Untitled

a guest
Nov 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. class BuildTravelPackage: UIViewController, UITableViewDataSource,UITableViewDelegate, UICollectionViewDelegate {
  2.  
  3. @IBOutlet var optionsTableView: UITableView!
  4.  
  5. var items = [[PackageOption]]()
  6.  
  7. override func viewDidLoad() {
  8. super.viewDidLoad()
  9.  
  10. let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.longPress(longPressGestureRecognizer:)))
  11. self.optionsTableView.addGestureRecognizer(longPressRecognizer)
  12.  
  13. let qGetCountry = PFQuery(className:"PackageOptions")
  14. let qGetEvents = PFQuery(className:"PackageOptions")
  15. qGetEvents.whereKey("type", contains: "Event")
  16.  
  17. qGetCountry.whereKey("type", contains: "Location")
  18. qGetCountry.whereKey("subType", contains: "Country")
  19.  
  20. qGetCountry.findObjectsInBackground { (items, error) in
  21. if error == nil{
  22. if items!.count > 0 {
  23. var developedOptions = [PackageOption]()
  24. for item in items!{
  25. let option = PackageOption.init()
  26. option.loadOnline(item: item)
  27. developedOptions.append(option)
  28. }
  29. self.items.append(developedOptions)
  30. self.optionsTableView.reloadData()
  31. }
  32. }
  33. }
  34. qGetEvents.findObjectsInBackground { (items, error) in
  35. if error == nil{
  36. if items!.count > 0 {
  37. var developedOptions = [PackageOption]()
  38. for item in items!{
  39.  
  40. let option = PackageOption.init()
  41. option.loadOnline(item: item)
  42. developedOptions.append(option)
  43. }
  44. self.items.append(developedOptions)
  45. self.optionsTableView.reloadData()
  46. }
  47.  
  48. }
  49. }
  50.  
  51.  
  52.  
  53. }
  54.  
  55. func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  56. cell.alpha = 0
  57. UIView.animate(withDuration: 1.0) {
  58. cell.alpha = 1.0
  59. }
  60. }
  61.  
  62. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  63. return 175
  64. }
  65.  
  66. func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
  67. return true
  68. }
  69.  
  70. func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
  71. return false
  72. }
  73.  
  74. func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
  75. return .none
  76. }
  77.  
  78. func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
  79. let item = items[sourceIndexPath.row]
  80. items.remove(at: sourceIndexPath.row)
  81. items.insert(item, at: destinationIndexPath.row)
  82. optionsTableView.isEditing = !optionsTableView.isEditing
  83.  
  84. }
  85.  
  86. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  87. let cell = optionsTableView.dequeueReusableCell(withIdentifier: "optionCell", for: indexPath) as! PackageOptionTableViewCell
  88. cell.collectionView.delegate = self
  89. cell.collectionView.dataSource = self
  90. cell.collectionView.tag = indexPath.row
  91. cell.collectionView.reloadData()
  92. return cell
  93. }
  94. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  95. return items.count
  96. }
  97.  
  98. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  99. print("Column:",indexPath.row)
  100. print("Row:",collectionView.tag)
  101. //highlght selected cell and load a new cell with infomation? Or load a uiview with date selection
  102. }
  103.  
  104. func longPress(longPressGestureRecognizer: UILongPressGestureRecognizer) {
  105.  
  106. if longPressGestureRecognizer.state == UIGestureRecognizerState.began {
  107.  
  108. let touchPoint = longPressGestureRecognizer.location(in: self.view)
  109. if let indexPath = optionsTableView.indexPathForRow(at: touchPoint) {
  110. optionsTableView.isEditing = !optionsTableView.isEditing
  111.  
  112. }
  113. }
  114. }
  115.  
  116. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  117. return items[collectionView.tag].count
  118. }
  119.  
  120. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  121. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "singleOptionCell", for: indexPath) as! OptionCollectionViewCell
  122. cell.image.image = items[collectionView.tag][indexPath.row].imageFile
  123. cell.label.text = items[collectionView.tag][indexPath.row].name
  124. return cell
  125. }
Add Comment
Please, Sign In to add comment