searchBarSearchButtonClicked 不能与 shouldChangeTextInRange 一起使用 [英] searchBarSearchButtonClicked doesn't work together with shouldChangeTextInRange
本文介绍了searchBarSearchButtonClicked 不能与 shouldChangeTextInRange 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 UISearchBar 委托方法,它自己工作(当它单独时调用).
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];
}
当我添加另一个 UISearchBar 委托方法时,前一个方法停止工作(不再调用).
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
推荐答案
我认为你应该将 \n 添加到 CHARACTERS
I think you should add \n to CHARACTERS
#define CHARACTERS @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz _-.\n"
这篇关于searchBarSearchButtonClicked 不能与 shouldChangeTextInRange 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文