开发者社区> 问答> 正文

IOS SWIFT-UIButton在自己的按钮单击事件中未被禁用

我使用基于用户输入的过滤方法搜索位置。一旦在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
        }

    }

展开
收起
游客5akardh5cojhg 2019-12-11 21:29:05 500 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载