gpt4 book ai didi

ios - 能够按字幕搜索

转载 作者:搜寻专家 更新时间:2023-11-01 07:13:19 26 4
gpt4 key购买 nike

我设置了搜索,这样我就可以按注释的标题进行搜索,但我也想按副标题 进行搜索!

代码:

func updateSearchResults(for searchController: UISearchController) {

matchingItems = []
guard let mapView = mapView,
let searchBarText = searchController.searchBar.text else { return }

for item in self.mapView!.annotations {
let title = item.title!!


if title.hasPrefix(searchBarText) && searchBarText != ""
{
matchingItems.append(item)

}
self.tableView.reloadData()
}

如何在我现在的代码中实现它?

感谢您的帮助!

最佳答案

你也可以像这样按字幕搜索:

func updateSearchResults(for searchController: UISearchController) {

guard let mapView = mapView,
let searchBarText = searchController.searchBar.text else { return }

matchingItems = self.mapView!.annotations.filter { annotation -> Bool in
if annotation.title!.range(of: searchBarText, options: .caseInsensitive) != nil {
return true
}

if annotation.subtitle!.range(of: searchBarText, options: .caseInsensitive) != nil {
return true
}

return false
}

self.tableView.reloadData()
}

关于ios - 能够按字幕搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43686785/

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