我使用数组和一个文本字段创建了表格 View 。 在textfield编辑tableview数据会根据textfield输入排序和过滤。如果table view有状态数据,如果我在textfield输入'A',所有tableview数据会被排序和显示所有以字母“A”开头的州名。请告诉我这方面的逻辑。
最佳答案
这个 Youtube 视频:https://www.youtube.com/watch?v=MgNRMcCWJhU&list=PLt2cCXacqzgfUAjHYnZ9rrPkih4NzAV4E&index=25
和站点链接可能会解决您的问题。
http://www.appcoda.com/custom-search-bar-tutorial/
你只需要不断地重新加载表格并在编辑功能时输入代码。
例如:
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
shouldShowSearchResults = true
tblSearchResults.reloadData()
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
let searchString = searchController.searchBar.text
// Filter the data array and get only those countries that match the search text.
filteredArray = dataArray.filter({ (country) -> Bool in
let countryText: NSString = country
return (countryText.rangeOfString(searchString, options: NSStringCompareOptions.CaseInsensitiveSearch).location) != NSNotFound
})
// Reload the tableview.
tblSearchResults.reloadData()
}
关于ios - 如何在文本字段编辑时过滤 TableView 数据 - IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44200653/