UITableView 在对象中搜索名称
UITableView Search For Name In Object
我正在尝试搜索从 Parse 检索到的对象数组,以在 UITableView
中显示结果。我尝试使用我在其他应用程序中使用的相同方法,但在那种情况下,它只是搜索一个字符串数组。
这是我目前的代码:
func filterContentForSearchText(searchText: NSString) {
let resultPredicate = NSPredicate(format: "SELF beginswith[cd] %@", searchText) //Use either contains or beginswith
searchResults = DataManager.sharedInstance.rideArray.name.filteredArrayUsingPredicate(resultPredicate)
}
func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -> Bool {
self.filterContentForSearchText(searchString)
return true
}
我明白为什么它不起作用,但我想不出解决问题的方法。我要在 'Ride' 对象中搜索的 属性 是名称。
谁能帮帮我?谢谢!
假设 rideArray
是一个具有 属性 name
的 Parse 对象数组,谓词应该是
NSPredicate(format: "name beginswith[cd] %@", searchText)
你用
过滤数组
rideArray.filteredArrayUsingPredicate(searchPredicate)
我正在尝试搜索从 Parse 检索到的对象数组,以在 UITableView
中显示结果。我尝试使用我在其他应用程序中使用的相同方法,但在那种情况下,它只是搜索一个字符串数组。
这是我目前的代码:
func filterContentForSearchText(searchText: NSString) {
let resultPredicate = NSPredicate(format: "SELF beginswith[cd] %@", searchText) //Use either contains or beginswith
searchResults = DataManager.sharedInstance.rideArray.name.filteredArrayUsingPredicate(resultPredicate)
}
func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -> Bool {
self.filterContentForSearchText(searchString)
return true
}
我明白为什么它不起作用,但我想不出解决问题的方法。我要在 'Ride' 对象中搜索的 属性 是名称。
谁能帮帮我?谢谢!
假设 rideArray
是一个具有 属性 name
的 Parse 对象数组,谓词应该是
NSPredicate(format: "name beginswith[cd] %@", searchText)
你用
过滤数组rideArray.filteredArrayUsingPredicate(searchPredicate)