UITableView+Extension.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // UITableView+Extension.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by mac on 2024/4/12.
  6. //
  7. import UIKit
  8. // MARK: - 基础扩展
  9. extension UITableView {
  10. // MARK: tableView 在 iOS 11 上的适配
  11. /// tableView 在 iOS 11 上的适配
  12. func tableViewNeverAdjustContentInset() {
  13. if #available(iOS 11, *) {
  14. self.estimatedRowHeight = 0
  15. self.estimatedSectionFooterHeight = 0
  16. self.estimatedSectionHeaderHeight = 0
  17. self.contentInsetAdjustmentBehavior = .never
  18. }
  19. }
  20. // MARK: 注册自定义cell
  21. /// 注册自定义cell
  22. /// - Parameter cellClass: UITableViewCell类型
  23. func register(cellClass: UITableViewCell.Type) {
  24. self.register(cellClass.self, forCellReuseIdentifier: cellClass.className)
  25. }
  26. // MARK: 创建UITableViewCell(注册后使用该方法)
  27. /// 创建UITableViewCell(注册后使用该方法)
  28. /// - Parameters:
  29. /// - cellType: UITableViewCell类型
  30. /// - indexPath: indexPath description
  31. /// - Returns: 返回UITableViewCell类型
  32. func dequeueReusableCell<T: UITableViewCell>(cellType: T.Type, cellForRowAt indexPath: IndexPath) -> T {
  33. return self.dequeueReusableCell(withIdentifier: cellType.className, for: indexPath) as! T
  34. }
  35. }