gpt4 book ai didi

ios - 点击搜索栏时,TableView 不会首次填充数据

转载 作者:行者123 更新时间:2023-11-29 02:07:05 27 4
gpt4 key购买 nike

我正在尝试通过 UISearchController 实现搜索栏并将委托(delegate)实现为

 func updateSearchResultsForSearchController(searchController: UISearchController) {

filteredTableData.removeAll(keepCapacity: true)

let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text)

let array = (tabledata as NSArray).filteredArrayUsingPredicate(searchPredicate)
filteredTableData = array as! [String]
self.tblView.reloadData()

}

但是,当我们点击搜索栏时,tableview 不会填充数据。否则一切正常。

我也尝试检查搜索栏的文本 >1 或不检查,但它在初始时有效,但在退格时给我错误。什么是黑客?

最佳答案

你应该实现UISearchbarDelegate's这个方法

  • searchBar:textDidChange:

所以你的台词是

 func searchBar(searchBar: UISearchBar, textDidChange searchText: String) 
{

filteredTableData.removeAll(keepCapacity: true)
let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchBar.text)

let array = (tabledata as NSArray).filteredArrayUsingPredicate(searchPredicate)
filteredTableData = array as! [String]
self.tblView.reloadData()
}

在此之前需要设置searchBar.delegate为self

关于ios - 点击搜索栏时,TableView 不会首次填充数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29675661/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com