1

I have the following UISearchBar delegate method that works by its own (it's called when it's alone).

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    [self downloadFruits:searchBar.text];
    [self.view endEditing:YES];
}

When I added another UISearchBar delegate method the previous one stopped working (it's not called anymore).

#define CHARACTERS @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz _-."
#define CHARACTERS_NUMBERS  [CHARACTERS stringByAppendingString:@"1234567890"]

-(BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSCharacterSet *unacceptedInput =
    [[NSCharacterSet characterSetWithCharactersInString:CHARACTERS_NUMBERS] invertedSet];
    // If array has more than one entry, there was at least one unacceptable character
    if ([[text componentsSeparatedByCharactersInSet:unacceptedInput] count] > 1)
        return NO;
    else
        return YES;
}

Each of them works well alone but together the first one (Search button) is not called

Alexey
  • 7,127
  • 9
  • 57
  • 94
  • That's odd. I feel those two should not interfere with each other (one is a button click, the other is text replacement) but just to be on the safe side, could you try to return YES from shouldChangeTextInRange and tell us the results (and then same with return NO) – Ege Akpinar Feb 26 '13 at 18:05

2 Answers2

3

I think you should add \n to CHARACTERS

#define CHARACTERS @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz _-.\n"
warchimede
  • 878
  • 6
  • 7
0

I think The second Method always return NO that's make the first not called

Hossam Ghareeb
  • 7,063
  • 3
  • 53
  • 64