杨锴
2024-09-10 1554b451f66120d81693eb722875e49a7e9a4186
XQMuse/Root/Home/VC/SearchVC.swift
@@ -58,13 +58,22 @@
            @IBOutlet weak var cacheSearchHei: NSLayoutConstraint!
            @IBOutlet weak var tf_search: UITextField!
            @IBOutlet weak var tableView: UITableView!
            private var hotWords = [String]()
            override func viewDidLoad() {
                        super.viewDidLoad()
                        title = "心泉·疗愈"
                        _ = SearchCache.readList()
                        cacheSearchCollectionView.reloadData()
                        Services.getHotWordList().subscribe(onNext: {data in
                                    if let m = data.data{
                                                self.hotWords = m
                                                self.tableView.reloadData()
                                    }
                        }).disposed(by: disposeBag)
            }
            override func viewDidDisappear(_ animated: Bool) {
@@ -90,6 +99,7 @@
                        tableView.delegate = self
                        tableView.dataSource = self
                        tableView.separatorStyle = .none
                        tableView.isScrollEnabled = false
                        tableView.backgroundColor = .clear
                        tableView.register(UINib(nibName: "SearchHotTCell", bundle: nil), forCellReuseIdentifier: "_SearchHotTCell")
@@ -128,19 +138,38 @@
                        tf_search.resignFirstResponder()
                        SearchCache.writeToList(tf_search.text!)
                        let vc = SearchContentVC(content: tf_search.text!)
                        jq_push(vc: vc)
            }
}
extension SearchVC:UITableViewDelegate & UITableViewDataSource{
            func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                        tf_search.text = hotWords[indexPath.row]
                        searchDone()
            }
            func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                        let cell = tableView.dequeueReusableCell(withIdentifier: "_SearchHotTCell", for: indexPath) as! SearchHotTCell
                        cell.selectionStyle = .none
                        cell.backgroundColor = .clear
                        cell.label_num.text = "\(indexPath.row + 1)"
                        cell.label_content.text = hotWords[indexPath.row]
                        if indexPath.row >= 3{
                                    cell.label_num.backgroundColor = UIColor(hexString: "#555555")
                                    cell.label_content.textColor = UIColor(hexString: "#555555")
                        }else{
                                    cell.label_num.backgroundColor = UIColor(hexString: "#0A4213")
                                    cell.label_content.textColor = UIColor(hexString: "#0A4213")
                        }
                        return cell
            }
            func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                        return 10
                        return hotWords.count
            }
            func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
@@ -151,6 +180,7 @@
extension SearchVC:UICollectionViewDelegate & UICollectionViewDataSource{
            func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                        tf_search.text = (SearchCache.array[indexPath.row] as! String)
                        searchDone()
            }