UISearchbar clearButton forces the keyboard to appear

后端 未结 12 1916
暖寄归人
暖寄归人 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:21

    Best solution from my experience is just to put a UIButton (with clear background and no text) above the system clear button and than connect an IBAction

    With autolayout its just more than easy

    - (IBAction)searchCancelButtonPressed:(id)sender {
    
        [self.searchBar resignFirstResponder];
        self.searchBar.text = @"";
    
        // some of my stuff
        self.model.fastSearchText = nil;
        [self.model fetchData];
        [self reloadTableViewAnimated:NO];
    
    }
    

提交回复
热议问题