iOS Swift-UIButton不会在其自己的按钮单击事件中被禁用

时间:2019-12-11 07:29:25

标签: ios swift uibutton

我正在使用基于用户输入的过滤方法搜索位置。一旦在UITextfiled中指定了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
                }
            matchedArray = Array(Set(matchedArray)) //Remove duplicates and assign
            dropButton.dataSource = matchedArray
            dropButton.show()
            self.searchGeoLocationBut.isEnabled = true
        }
    }

0 个答案:

没有答案