我想从自定义值自动完成文本字段
在这里研究了 Google 和 SO UITextField Autocomplete - iPhone SDK
我试过这个:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([string isEqualToString:@"Fac"]) {
_clientField.text = @"Factory";
}
return YES;
}
问题是我没有输入预测值Factory
,只有输入的值Fac
编辑
根据答案尝试了这个...
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([string isEqualToString:@"Fac"]) {
_clientField.text = [_clientField.text stringByReplacingCharactersInRange:range
withString:@"Factory"];
}
return NO;
}
还是一样