TableViewInContainerViewController.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // TableViewInContainerViewController.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 TableViewInContainerViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UIPopoverPresentationControllerDelegate {
  10. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  11. return 30
  12. }
  13. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  14. let identifier = "TestCell"
  15. var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
  16. if cell == nil {
  17. cell = UITableViewCell(style: .default, reuseIdentifier: identifier)
  18. cell?.backgroundColor = UIColor.clear
  19. let contentView: UIView! = cell?.contentView
  20. let textField = UITextField(frame: CGRect(x: 10, y: 0, width: contentView.frame.size.width-20, height: 33))
  21. textField.autoresizingMask = [.flexibleBottomMargin, .flexibleTopMargin, .flexibleWidth]
  22. textField.center = contentView.center
  23. textField.backgroundColor = UIColor.clear
  24. textField.borderStyle = .roundedRect
  25. textField.tag = 123
  26. cell?.contentView.addSubview(textField)
  27. }
  28. let textField = cell?.viewWithTag(123) as? UITextField
  29. textField?.placeholder = "Cell \((indexPath as NSIndexPath).row)"
  30. return cell!
  31. }
  32. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  33. if let identifier = segue.identifier {
  34. if identifier == "SettingsNavigationController" {
  35. let controller = segue.destination
  36. controller.modalPresentationStyle = .popover
  37. controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
  38. let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
  39. controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
  40. controller.popoverPresentationController?.delegate = self
  41. }
  42. }
  43. }
  44. func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
  45. return .none
  46. }
  47. func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
  48. self.view.endEditing(true)
  49. }
  50. override var shouldAutorotate: Bool {
  51. return true
  52. }
  53. }