我使用基于用户输入的过滤方法搜索位置。一旦在UITextfield中给出InOut,用户就必须为该按钮设置标签。以下是按钮单击事件,我没有看到按钮没有被禁用后,同一按钮被点击。
@IBAction func searchGeoButtonClicked(_ sender: UIButton) {
var matchedArray = ["No results"]
var flag = false
print("Button clicked")
self.searchGeoLocationBut.isEnabled = false
dropButton.hide()
searchGeoTextField.shake()
if let searchText = searchGeoTextField.text, !searchText.isEmpty
{
matchedArray.removeAll()
let unichar = "→"
_ = locdata.filter { (location: Location) -> Bool in
print("Inside search filter")
if location.country.lowercased().contains(searchText.lowercased().trimmingCharacters(in: .whitespacesAndNewlines))
{
flag = true
matchedArray.append(location.country)
}
else if location.state.lowercased().contains(searchText.lowercased().trimmingCharacters(in: .whitespacesAndNewlines))
{
flag = true
matchedArray.append(location.state + unichar + location.country )
}
else if location.district.lowercased().contains(searchText.lowercased().trimmingCharacters(in: .whitespacesAndNewlines))
{
flag = true
matchedArray.append(location.district + unichar + location.state + unichar + location.country )
}
else if location.subdistrict.lowercased().contains(searchText.lowercased().trimmingCharacters(in: .whitespacesAndNewlines))
{
flag = true
matchedArray.append(location.subdistrict + unichar + location.district + unichar + location.state + unichar + location.country )
}
return flag
// return location.country.contains(searchText) || location.state.contains(searchText) || location.district.contains(searchText) || location.subdistrict.contains(searchText)
}
matchedArray = Array(Set(matchedArray)) //Remove duplicates and assign
dropButton.dataSource = matchedArray
dropButton.show()
self.searchGeoLocationBut.isEnabled = true
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。