UISearchbar clearButton forces the keyboard to appear

后端 未结 12 1939
暖寄归人
暖寄归人 2020-11-30 20:40

I have a UISearchBar which acts as a live filter for a table view. When the keyboard is dismissed via endEditing:, the query text and the gray circular \"clear\" button rem

12条回答
  •  鱼传尺愫
    2020-11-30 21:32

    A Swift version of @boliva 's answer.

    class MySearchContentController: UISearchBarDelegate {
    
        private var searchBarShouldBeginEditing = true
    
        func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
            searchBarShouldBeginEditing = searchBar.isFirstResponder
        }
    
        func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
            defer {
                searchBarShouldBeginEditing = true
            }
            return searchBarShouldBeginEditing
        }
    }
    

提交回复
热议问题