私は Algolia InstantSearch を使用しており、HitsTableViewController はデータのリストを適切に表示していますが、結果はキーストロークごとに変化しません。検索バーに文字を入力するたびに結果を変更する方法を知っている人はいますか? InstantSearch のドキュメントに書かれていることはすべて実行しました。
これがコードです
import UIKit
import InstantSearch
struct BestBuyItem: Codable {
let name: String
}
struct BestBuyTableViewCellConfigurator: TableViewCellConfigurable {
let model: BestBuyItem
init(model: BestBuyItem, indexPath: IndexPath) {
self.model = model
}
func configure(_ cell: UITableViewCell) {
cell.textLabel?.text = model.name
}
}
typealias BestBuyHitsViewController = HitsTableViewController<BestBuyTableViewCellConfigurator>
class ViewController: UIViewController {
let searcher = SingleIndexSearcher(appID: "latency",
apiKey: "1f6fd3a6fb973cb08419fe7d288fa4db",
indexName: "bestbuy")
lazy var searchController: UISearchController = .init(searchResultsController: hitsViewController)
lazy var searchConnector: SingleIndexSearchConnector<BestBuyItem> = .init(searcher: searcher,
searchController: searchController,
hitsController: hitsViewController,
filterState: filterState)
let hitsViewController: BestBuyHitsViewController = .init()
let statsInteractor: StatsInteractor = .init()
let filterState: FilterState = .init()
lazy var categoryConnector: FacetListConnector = .init(searcher: searcher,
filterState: filterState,
attribute: "category",
operator: .or,
controller: categoryListController,
presenter: FacetListPresenter(sortBy: [.isRefined]))
lazy var categoryListController: FacetListTableController = .init(tableView: categoryTableViewController.tableView)
let categoryTableViewController: UITableViewController = .init()
override func viewDidLoad() {
super.viewDidLoad()
searchConnector.connect()
categoryConnector.connect()
statsInteractor.connectSearcher(searcher)
statsInteractor.connectController(self)
searcher.search()
setupUI()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
searchController.searchBar.becomeFirstResponder()
}
func setupUI() {
view.backgroundColor = .white
navigationItem.searchController = searchController
navigationItem.rightBarButtonItem = .init(title: "Category", style: .plain, target: self, action: #selector(showFilters))
searchController.hidesNavigationBarDuringPresentation = false
searchController.showsSearchResultsController = true
searchController.automaticallyShowsCancelButton = false
categoryTableViewController.title = "Category"
}
@objc func showFilters() {
let navigationController = UINavigationController(rootViewController: categoryTableViewController)
categoryTableViewController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissFilters))
present(navigationController, animated: true, completion: .none)
}
@objc func dismissFilters() {
categoryTableViewController.navigationController?.dismiss(animated: true, completion: .none)
}
}
extension ViewController: StatsTextController {
func setItem(_ item: String?) {
title = item
}
}
助けてくれる人に本当に感謝します、ありがとう