我有以下 UISearchBar 委托方法,它自己工作(它在单独时被调用)。
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[self downloadFruits:searchBar.text];
[self.view endEditing:YES];
}
当我添加另一个 UISearchBar 委托方法时,前一个委托方法停止工作(不再调用它)。
#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;
}
它们中的每一个都可以单独使用,但不调用第一个(搜索按钮)