我正在尝试实施 UISearchBar 委托
-(BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string{
NSCharacterSet *set = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzQWERTYUIOPLKJHGFDSAZXCVBNM0123456789!@#$%^&*()_+./?'\"\\*- "] invertedSet];
const char * _char = [string cStringUsingEncoding:NSUTF8StringEncoding];
string = [[string componentsSeparatedByCharactersInSet:set] componentsJoinedByString:@""];
int isBackSpace = strcmp(_char, "\b");
if((string!=nil && ![string isEqualToString:@""]) || isBackSpace == -8)
{
return YES;
}
return NO;
}
并点击搜索按钮
-(void) searchBarSearchButtonClicked:(UISearchBar *)searchBarSender{[mySearchBar resignFirstResponder];
}
但 searchBarSearchButtonClicked 委托永远不会被解雇。
我尝试删除 shouldChangeTextInRange 然后调用它。我做错了什么?