我的应用中有一个搜索框。它的类是UITextField而不是UISearchBar。我想将其设置为搜索栏。对于每次输入的每个字符串,使用该字符串执行(void)搜索功能。但我不知道该怎么做。实际上我想在输入每个字符后调用(void)搜索。
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[self Search];
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
[self Search];
}
答案 0 :(得分:2)
您可以使用shouldChangeCharactersInRange获取当前用户输入
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString * searhQuery = [[textField text] stringByReplacingCharactersInRange:range withString:string];
[self Search:searhQuery];
return YES;
}