Search code examples
uitableviewios6ios7

Multiple search bars in iOS with an And operation


I want to add two search bars for same uitableview..Suppose one search bar will filter the tableview and than if user will enter in the second search bar than now the remaining result will be filter, I have seen so many questions about it but nothing found very useful. Should I have to play with UITextFields or is there any easy solution exist for this? If any one can refer some tutorial or some suggestion for this? And means "And the result of one search bar with the second one"


Solution

  • You could implement this on change delegate method ( binding your textfields from xib to your owner ) in your viewcontroller using UITextFieldDelegate protocol, then filter datasource table with search fields

     - (BOOL)textField:(UITextField *)textField 
                    shouldChangeCharactersInRange:(NSRange)range 
                    replacementString:(NSString *)string 
        {
    
            if (textField == self.firstSearchField)
            {
                self.nameFilter = textField.text;
                // ....
            }else if (textField == self.secondSearchField)
            {
                self.surnameFilter = textField.text;
                // ....
            }
    
            // filter your datasource, then reloading your tableview (table.reloadData) 
    
            return YES;
        }