这个代码我已经知道它只是在键盘敲击sjows结果的UIsearchControl中输入文本后才在搜索栏中显示结果。
我希望在搜索中每个字符的输入应该使用哪个委托
任何人都可以帮助我。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
SEachResultContoller=1;
NSString *searchBarText=searchContollerObj.searchBar.text;
// searching by serial no
if(SEachResultContoller==1)
{
if(searchBarText == nil)
{
resultArray=[reasourceDataToShowOnView mutableCopy];
}
else
{
NSMutableArray *resultArray1=[[ NSMutableArray alloc] init];
for(NSDictionary *dict in reasourceDataToShowOnView)
{
if([dict [SERIALNO] containsString:searchBarText])
{
[resultArray1 addObject:dict];
}
resultArray=resultArray1;
DDLogDebug(@" search data %@",resultArray);
}
}
[ _resousetableView reloadData];
}
// searchng by barcode
else if (searchByBarCode==1)
{
if(searchBarText == nil)
{
resultArray=[reasourceDataToShowOnView mutableCopy];
}
else
{
NSMutableArray *resultArray1=[[ NSMutableArray alloc] init];
for(NSDictionary *dict in reasourceDataToShowOnView)
{
if([dict [BARCODE] containsString:searchBarText])
{
[resultArray1 addObject:dict];
}
resultArray=resultArray1;
DDLogDebug(@" search data %@",resultArray);
}
}
[ _resousetableView reloadData];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
SEachResultContoller=1;
NSString *searchBarText=searchContollerObj.searchBar.text;
// searching by serial no
if(SEachResultContoller==1)
{
if(searchBarText == nil)
{
resultArray=[reasourceDataToShowOnView mutableCopy];
}
else
{
NSMutableArray *resultArray1=[[ NSMutableArray alloc] init];
for(NSDictionary *dict in reasourceDataToShowOnView)
{
if([dict [SERIALNO] containsString:searchBarText])
{
[resultArray1 addObject:dict];
}
resultArray=resultArray1;
DDLogDebug(@" search data %@",resultArray);
}
}
[ _resousetableView reloadData];
}
// searchng by barcode
else if (searchByBarCode==1)
{
if(searchBarText == nil)
{
resultArray=[reasourceDataToShowOnView mutableCopy];
}
else
{
NSMutableArray *resultArray1=[[ NSMutableArray alloc] init];
for(NSDictionary *dict in reasourceDataToShowOnView)
{
if([dict [BARCODE] containsString:searchBarText])
{
[resultArray1 addObject:dict];
}
resultArray=resultArray1;
DDLogDebug(@" search data %@",resultArray);
}
}
[ _resousetableView reloadData];
}
}
//按下输入btn
后显示结果-
(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
SEachResultContoller=1;
NSString *searchBarText=searchBar.text;
// searching by serial no
if(SEachResultContoller==1)
{
if(searchBarText == nil)
{
resultArray=[reasourceDataToShowOnView mutableCopy];
}
else
{
NSMutableArray *resultArray1=[[ NSMutableArray alloc] init];
for(NSDictionary *dict in reasourceDataToShowOnView)
{
if([dict [SERIALNO] containsString:searchBarText])
{
[resultArray1 addObject:dict];
}
resultArray=resultArray1;
DDLogDebug(@" search data %@",resultArray);
}
}
[ _resousetableView reloadData];
}
// searchng by barcode
else if (searchByBarCode==1)
{
if(searchBarText == nil)
{
resultArray=[reasourceDataToShowOnView mutableCopy];
}
else
{
NSMutableArray *resultArray1=[[ NSMutableArray alloc] init];
for(NSDictionary *dict in reasourceDataToShowOnView)
{
if([dict [BARCODE] containsString:searchBarText])
{
[resultArray1 addObject:dict];
}
resultArray=resultArray1;
DDLogDebug(@" search data %@",resultArray);
}
}
[ _resousetableView reloadData];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
SEachResultContoller=1;
NSString *searchBarText=searchContollerObj.searchBar.text;
// searching by serial no
if(SEachResultContoller==1)
{
if(searchBarText == nil)
{
resultArray=[reasourceDataToShowOnView mutableCopy];
}
else
{
NSMutableArray *resultArray1=[[ NSMutableArray alloc] init];
for(NSDictionary *dict in reasourceDataToShowOnView)
{
if([dict [SERIALNO] containsString:searchBarText])
{
[resultArray1 addObject:dict];
}
resultArray=resultArray1;
DDLogDebug(@" search data %@",resultArray);
}
}
[ _resousetableView reloadData];
}
// searchng by barcode
else if (searchByBarCode==1)
{
if(searchBarText == nil)
{
resultArray=[reasourceDataToShowOnView mutableCopy];
}
else
{
NSMutableArray *resultArray1=[[ NSMutableArray alloc] init];
for(NSDictionary *dict in reasourceDataToShowOnView)
{
if([dict [BARCODE] containsString:searchBarText])
{
[resultArray1 addObject:dict];
}
resultArray=resultArray1;
DDLogDebug(@" search data %@",resultArray);
}
}
[ _resousetableView reloadData];
}
哪个委托方法或如何实施它可以帮助我
答案 0 :(得分:0)
首先调用此委托方法
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
// Your implementation
return YES;
}
如果您不想显示键盘返回NO。
另请尝试本教程Implement Search Bar