Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BuildTravelPackage: UIViewController, UITableViewDataSource,UITableViewDelegate, UICollectionViewDelegate {
- @IBOutlet var optionsTableView: UITableView!
- var items = [[PackageOption]]()
- override func viewDidLoad() {
- super.viewDidLoad()
- let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.longPress(longPressGestureRecognizer:)))
- self.optionsTableView.addGestureRecognizer(longPressRecognizer)
- let qGetCountry = PFQuery(className:"PackageOptions")
- let qGetEvents = PFQuery(className:"PackageOptions")
- qGetEvents.whereKey("type", contains: "Event")
- qGetCountry.whereKey("type", contains: "Location")
- qGetCountry.whereKey("subType", contains: "Country")
- qGetCountry.findObjectsInBackground { (items, error) in
- if error == nil{
- if items!.count > 0 {
- var developedOptions = [PackageOption]()
- for item in items!{
- let option = PackageOption.init()
- option.loadOnline(item: item)
- developedOptions.append(option)
- }
- self.items.append(developedOptions)
- self.optionsTableView.reloadData()
- }
- }
- }
- qGetEvents.findObjectsInBackground { (items, error) in
- if error == nil{
- if items!.count > 0 {
- var developedOptions = [PackageOption]()
- for item in items!{
- let option = PackageOption.init()
- option.loadOnline(item: item)
- developedOptions.append(option)
- }
- self.items.append(developedOptions)
- self.optionsTableView.reloadData()
- }
- }
- }
- }
- func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
- cell.alpha = 0
- UIView.animate(withDuration: 1.0) {
- cell.alpha = 1.0
- }
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 175
- }
- func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
- return true
- }
- func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
- return false
- }
- func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
- return .none
- }
- func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
- let item = items[sourceIndexPath.row]
- items.remove(at: sourceIndexPath.row)
- items.insert(item, at: destinationIndexPath.row)
- optionsTableView.isEditing = !optionsTableView.isEditing
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = optionsTableView.dequeueReusableCell(withIdentifier: "optionCell", for: indexPath) as! PackageOptionTableViewCell
- cell.collectionView.delegate = self
- cell.collectionView.dataSource = self
- cell.collectionView.tag = indexPath.row
- cell.collectionView.reloadData()
- return cell
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return items.count
- }
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- print("Column:",indexPath.row)
- print("Row:",collectionView.tag)
- //highlght selected cell and load a new cell with infomation? Or load a uiview with date selection
- }
- func longPress(longPressGestureRecognizer: UILongPressGestureRecognizer) {
- if longPressGestureRecognizer.state == UIGestureRecognizerState.began {
- let touchPoint = longPressGestureRecognizer.location(in: self.view)
- if let indexPath = optionsTableView.indexPathForRow(at: touchPoint) {
- optionsTableView.isEditing = !optionsTableView.isEditing
- }
- }
- }
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return items[collectionView.tag].count
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "singleOptionCell", for: indexPath) as! OptionCollectionViewCell
- cell.image.image = items[collectionView.tag][indexPath.row].imageFile
- cell.label.text = items[collectionView.tag][indexPath.row].name
- return cell
- }
Add Comment
Please, Sign In to add comment