ios - 如何在文本字段编辑时过滤 TableView 数据 - IOS

标签 ios iphone uitableview swift3 xcode8

我使用数组和一个文本字段创建了表格 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/

相关文章:

iphone - IOS 中 glColor4f OpenGl 函数的应用程序崩溃

ios - UICollectionView 与 2 组部分 headerViews

Swift:让详细 View Controller 知道数组可能存在也可能不存在

ios - 有什么方便的方法可以管理 iOS 应用程序中的配色方案吗?

iphone - 文件管理器 - 找不到文件 - Objective C

ios - Swift - 表达式太复杂,无法在合理的时间内解决;考虑将表达式分解为不同的子表达式

iphone - 如何保存拍摄的照片

iphone - 如何从 iPhone 通讯录中检索手机号码。

objective-c - 如何显示来自 NSMutableDictionary 的 NSMutableArray 的动态值列表?

ios - 缩放 super 层时如何不缩放 CATextLayers