// // QSLMineFuncView.swift // QuickSearchLocation // // Created by Destiny on 2024/4/16. // import UIKit protocol QSLMineFuncViewDelegate: NSObjectProtocol { func didSelectRowAt(indexPath: IndexPath) } class QSLMineFuncView: UIView { struct UX { static let collectionWidth = (QSLConst.qsl_kScreenW - 24.0) / 4 static let collectionHeight = 76.0 } weak var delegate: QSLMineFuncViewDelegate? var viewModel: QSLMineViewModel? lazy var funcTableView: UITableView = { let tableView = UITableView(frame: .zero, style: .grouped) tableView.backgroundColor = .clear tableView.separatorStyle = .none tableView.showsVerticalScrollIndicator = false tableView.delegate = self tableView.dataSource = self tableView.tableViewNeverAdjustContentInset() tableView.bounces = false tableView.isUserInteractionEnabled = true tableView.isScrollEnabled = false tableView.contentInsetAdjustmentBehavior = .never tableView.register(cellClass: QSLMineFuncTableViewCell.self) return tableView }() override init(frame: CGRect) { super.init(frame: frame) setUpUI() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } // MARK: - 设置UI extension QSLMineFuncView { func setUpUI() { addSubview(funcTableView) self.addRadius(radius: 6) self.backgroundColor = .white funcTableView.snp.makeConstraints { make in make.left.right.bottom.equalTo(0) make.top.equalTo(0) } } } // MARK: - 设置Tableview extension QSLMineFuncView: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { guard let funcLists = viewModel?.funcLists else { return 0 } return funcLists.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(cellType: QSLMineFuncTableViewCell.self, cellForRowAt: indexPath) cell.selectionStyle = .none let funcModel = viewModel?.funcLists[indexPath.row] cell.cellDict = funcModel return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { delegate?.didSelectRowAt(indexPath: indexPath) } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return QSLMineViewModel.UX.funcCellHeight } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 14.rpx } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return 14.rpx } }