From e15c976316feef72ff9bcabce38e0a078f9505db Mon Sep 17 00:00:00 2001 From: 杨锴 <841720330@qq.com> Date: 星期四, 12 九月 2024 18:18:03 +0800 Subject: [PATCH] fix API --- XQMuse/Root/Pavilion/VC/PavilionSearchVC.swift | 23 ++++++++++++++++++----- 1 files changed, 18 insertions(+), 5 deletions(-) diff --git a/XQMuse/Root/Pavilion/VC/PavilionSearchVC.swift b/XQMuse/Root/Pavilion/VC/PavilionSearchVC.swift index 42c9e3f..32f3d82 100644 --- a/XQMuse/Root/Pavilion/VC/PavilionSearchVC.swift +++ b/XQMuse/Root/Pavilion/VC/PavilionSearchVC.swift @@ -7,17 +7,23 @@ import UIKit import JQTools +import RxSwift +import RxRelay +import CoreLocation class PavilionSearchVC: BaseVC { @IBOutlet weak var tf_search: UITextField! @IBOutlet weak var collectionView: UICollectionView! + var viewModel:PavilionViewModel? + override func viewDidLoad() { super.viewDidLoad() title = "疗愈馆" tf_search.delegate = self tf_search.returnKeyType = .search + viewModel?.configure(collectionView) } override func setUI() { @@ -32,10 +38,17 @@ collectionView.contentInset = UIEdgeInsets(top: 0, left: 28.5, bottom: 0, right: 28.5) collectionView.register(UINib(nibName: "PavilionItemCell", bundle: nil), forCellWithReuseIdentifier: "_PavilionItemCell") } + + @IBAction func cancelAction(_ sender: UIButton) { + self.navigationController?.popViewController() + } } extension PavilionSearchVC:UITextFieldDelegate{ func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() + viewModel?.search.accept(textField.text!) + viewModel?.beginRefresh() return true } } @@ -43,21 +56,21 @@ extension PavilionSearchVC:UICollectionViewDataSource{ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - let detailVC = PavilionDetailVC() + let model = viewModel!.dataSource.value!.list[indexPath.row] + let detailVC = PavilionDetailVC(id: model.id) push(vc: detailVC) } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - + let model = viewModel!.dataSource.value!.list[indexPath.row] let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_PavilionItemCell", for: indexPath) as! PavilionItemCell cell.backgroundColor = .jq_randomColor cell.jq_cornerRadius = 16 + cell.setPavilionDetailModel(model) return cell - } - func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 10 + return viewModel?.dataSource.value?.list.count ?? 0 } } -- Gitblit v1.7.1