ExampleTableViewController.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 as NSIndexPath).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 as NSIndexPath).section) \((indexPath as NSIndexPath).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 as NSIndexPath).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. if let identifier = segue.identifier {
  46. if identifier == "SettingsNavigationController" {
  47. let controller = segue.destination
  48. controller.modalPresentationStyle = .popover
  49. controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
  50. let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
  51. controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
  52. controller.popoverPresentationController?.delegate = self
  53. }
  54. }
  55. }
  56. func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
  57. return .none
  58. }
  59. func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
  60. self.view.endEditing(true)
  61. }
  62. override var shouldAutorotate: Bool {
  63. return true
  64. }
  65. }