ExampleTableViewController.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // ExampleTableViewController.swift
  3. // IQKeyboardManager
  4. //
  5. // Created by InfoEnum02 on 20/04/15.
  6. // Copyright (c) 2015 Iftekhar. All rights reserved.
  7. //
  8. import UIKit
  9. class ExampleTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UIPopoverPresentationControllerDelegate {
  10. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  11. return 10
  12. }
  13. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  14. if (indexPath.row % 2) == 0 {
  15. return 40
  16. } else {
  17. return 160
  18. }
  19. }
  20. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  21. let identifier = "\(indexPath.section) \(indexPath.row)"
  22. var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
  23. if cell == nil {
  24. cell = UITableViewCell(style: .default, reuseIdentifier: identifier)
  25. cell?.backgroundColor = UIColor.clear
  26. cell?.selectionStyle = .none
  27. let contentView: UIView! = cell?.contentView
  28. if (indexPath.row % 2) == 0 {
  29. let textField = UITextField(frame: CGRect(x: 5, y: 5, width: contentView.frame.size.width-10, height: 30))
  30. textField.autoresizingMask = [.flexibleBottomMargin, .flexibleTopMargin, .flexibleWidth]
  31. textField.placeholder = identifier
  32. textField.backgroundColor = UIColor.clear
  33. textField.borderStyle = .roundedRect
  34. cell?.contentView.addSubview(textField)
  35. } else {
  36. let textView = UITextView(frame: contentView.bounds.insetBy(dx: 5, dy: 5))
  37. textView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
  38. textView.text = "Sample Text"
  39. cell?.contentView.addSubview(textView)
  40. }
  41. }
  42. return cell!
  43. }
  44. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  45. guard let identifier = segue.identifier else {
  46. return
  47. }
  48. if identifier == "SettingsNavigationController" {
  49. let controller = segue.destination
  50. controller.modalPresentationStyle = .popover
  51. controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
  52. let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
  53. controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
  54. controller.popoverPresentationController?.delegate = self
  55. }
  56. }
  57. func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
  58. return .none
  59. }
  60. func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
  61. self.view.endEditing(true)
  62. }
  63. override var shouldAutorotate: Bool {
  64. return true
  65. }
  66. }