gpt4 book ai didi

ios - 使 UISearchBar 在两个不同的字段上进行搜索

转载 作者:行者123 更新时间:2023-11-29 01:41:36 25 4
gpt4 key购买 nike

我正在使用 UISearchBarUITableView 的单元格中搜索特定文本。我正在从一组对象中填充这些单元格的数据。这些对象每个都有三个不同的属性,其中两个是 String 类型,而第三个是 UIImage。有什么方法可以让 UISearchBar 在对象的两个文本字段上搜索文本,而无需询问用户他们希望在哪个字段上执行搜索?

最佳答案

有一种简单的方法可以过滤数组,您可以完全决定数组的对象何时应该在新数组中:

data = data.filter({( aObject: YourClass) -> Bool in

// code for checking if the aObject should be in the data array
// then return true if it should be in the new array and false if not
// For example your return statement could be something like this:

return (aObject.firstString.lowercaseString.rangeOfString(searchText.lowercaseString) != nil) || (aObject.secondString.lowercaseString.rangeOfString(searchText.lowercaseString) != nil)
})

关于ios - 使 UISearchBar 在两个不同的字段上进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32325665/

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