ViewController+TableView.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // ViewController+TableView.swift
  3. // SheeeeeeeeetExample
  4. //
  5. // Created by Daniel Saidi on 2017-12-02.
  6. // Copyright © 2017 Daniel Saidi. All rights reserved.
  7. //
  8. /*
  9. These extensions are only used by the example app, to setup
  10. the main view controller's table view handling.
  11. */
  12. import UIKit
  13. import Sheeeeeeeeet
  14. // MARK: - UITableViewDataSource
  15. extension ViewController: UITableViewDataSource {
  16. func numberOfSections(in tableView: UITableView) -> Int {
  17. return 1
  18. }
  19. func option(at indexPath: IndexPath) -> TableViewOption {
  20. return tableViewOptions[indexPath.row]
  21. }
  22. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  23. return tableViewOptions.count
  24. }
  25. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  26. let option = self.option(at: indexPath)
  27. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
  28. cell.tintColor = .darkGray
  29. cell.imageView?.image = option.image
  30. cell.textLabel?.text = option.title
  31. cell.detailTextLabel?.text = option.description
  32. return cell
  33. }
  34. }
  35. // MARK: - UITableViewDelegate
  36. extension ViewController: UITableViewDelegate {
  37. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  38. return 70
  39. }
  40. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  41. tableView.deselectRow(at: indexPath, animated: true)
  42. guard let cell = tableView.cellForRow(at: indexPath) else { return }
  43. guard let sheet = actionSheet(at: indexPath) else { return }
  44. sheet.presenter.events.didDismissWithBackgroundTap = { print("Background tap!") }
  45. sheet.present(in: self, from: cell.textLabel)
  46. }
  47. }