ViewController+TableView.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. import UIKit
  9. import Sheeeeeeeeet
  10. // MARK: - UITableViewDataSource
  11. extension ViewController: UITableViewDataSource {
  12. func numberOfSections(in tableView: UITableView) -> Int {
  13. return 1
  14. }
  15. func option(at indexPath: IndexPath) -> TableViewOption {
  16. return tableViewOptions[indexPath.row]
  17. }
  18. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  19. return tableViewOptions.count
  20. }
  21. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  22. let option = self.option(at: indexPath)
  23. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
  24. cell.tintColor = .darkGray
  25. cell.imageView?.image = option.image
  26. cell.textLabel?.text = option.title
  27. cell.detailTextLabel?.text = option.description
  28. return cell
  29. }
  30. }
  31. // MARK: - UITableViewDelegate
  32. extension ViewController: UITableViewDelegate {
  33. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  34. return 70
  35. }
  36. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  37. tableView.deselectRow(at: indexPath, animated: true)
  38. guard let cell = tableView.cellForRow(at: indexPath) else { return }
  39. guard let sheet = actionSheet(at: indexPath) else { return }
  40. sheet.presenter.events.didDismissWithBackgroundTap = { print("Background tap!") }
  41. sheet.present(in: self, from: cell.textLabel)
  42. }
  43. }