QSLMineFuncView.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // QSLMineFuncView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/4/16.
  6. //
  7. import UIKit
  8. protocol QSLMineFuncViewDelegate: NSObjectProtocol {
  9. func didSelectRowAt(indexPath: IndexPath)
  10. }
  11. class QSLMineFuncView: UIView {
  12. struct UX {
  13. static let collectionWidth = (QSLConst.qsl_kScreenW - 24.0) / 4
  14. static let collectionHeight = 76.0
  15. }
  16. weak var delegate: QSLMineFuncViewDelegate?
  17. var viewModel: QSLMineViewModel?
  18. lazy var funcTableView: UITableView = {
  19. let tableView = UITableView(frame: .zero, style: .grouped)
  20. tableView.backgroundColor = .clear
  21. tableView.separatorStyle = .none
  22. tableView.showsVerticalScrollIndicator = false
  23. tableView.delegate = self
  24. tableView.dataSource = self
  25. tableView.tableViewNeverAdjustContentInset()
  26. tableView.bounces = false
  27. tableView.isUserInteractionEnabled = true
  28. tableView.isScrollEnabled = false
  29. tableView.contentInsetAdjustmentBehavior = .never
  30. tableView.register(cellClass: QSLMineFuncTableViewCell.self)
  31. return tableView
  32. }()
  33. override init(frame: CGRect) {
  34. super.init(frame: frame)
  35. setUpUI()
  36. }
  37. required init?(coder: NSCoder) {
  38. fatalError("init(coder:) has not been implemented")
  39. }
  40. }
  41. // MARK: - 设置UI
  42. extension QSLMineFuncView {
  43. func setUpUI() {
  44. addSubview(funcTableView)
  45. self.addRadius(radius: 6)
  46. self.backgroundColor = .white
  47. funcTableView.snp.makeConstraints { make in
  48. make.left.right.bottom.equalTo(0)
  49. make.top.equalTo(0)
  50. }
  51. }
  52. }
  53. // MARK: - 设置Tableview
  54. extension QSLMineFuncView: UITableViewDelegate, UITableViewDataSource {
  55. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  56. guard let funcLists = viewModel?.funcLists else { return 0 }
  57. return funcLists.count
  58. }
  59. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  60. let cell = tableView.dequeueReusableCell(cellType: QSLMineFuncTableViewCell.self, cellForRowAt: indexPath)
  61. cell.selectionStyle = .none
  62. let funcModel = viewModel?.funcLists[indexPath.row]
  63. cell.cellDict = funcModel
  64. return cell
  65. }
  66. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  67. delegate?.didSelectRowAt(indexPath: indexPath)
  68. }
  69. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  70. return QSLMineViewModel.UX.funcCellHeight
  71. }
  72. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  73. return 14.rpx
  74. }
  75. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  76. return 14.rpx
  77. }
  78. }