我 Main.storyboard
中的 UISearchBar and SearchDisplayController
嵌入 UIViewController
s' UIView
. 下面我有 UITableView
. 我正在尝试使用 RxSwift
将用户输入从 UISearchBar
直接传送到 UITableView
,并在中间执行结果过滤 . 几乎它是我试图实现的自动完成功能 . 不知怎的,我收到一个错误:
线程1:致命错误:从Optional()转换为UISearchBarDelegate失败
这是我的代码:
private func setUpAutocomplete() {
// Define intput stream
searchBar.rx.text
.orEmpty
.map({
(query: String) -> [String] in
let res = AllGenes.filter { $0.hasPrefix(query) }
return res
})
.bind(to: tableView.rx.items(cellIdentifier: cellIdentifier,
cellType: GeneSeachTableViewCell.self)) { row, gene, cell in
cell.textLabel?.text = "\(gene) \(row)"
}
.disposed(by: disposeBag)
}
我在这做错了什么?任何建议将不胜感激 .
1 回答
我无法直接输入输入,但是分两步完成:
哪里
shownGenes = Variable<[String]>([])
. 我也删除了UISearchBar and SearchDisplayController
并将其替换为UISearchBar
.