定義済みUItextfield
の文字列に基づいて値を自動補完する があります。複数の単語が最初の stringcurrentString
にある場合、結果の表示には最後の char がcurrentString
追加されます。
したがって、サンプルコードでは
と入力するNo
と、UITextField
結果のテキストはNote todayt
(文字列に追加された 2 番目の単語の最後の文字) になります。
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *currentString = [_txt.text stringByReplacingCharactersInRange:range withString:string];
NSString *currentString = [_txt.text stringByReplacingCharactersInRange:range withString:string];
if ([currentString isEqualToString:@"No t"]) {
textField.text = @"Note today";
この動作を回避する方法はありますか?
私が試してみました
if(_txt.text.length>1)
{
_txt.text =[textField.text substringToIndex:[textField.text length] - 1];
}
と
if(_txt.text.length>1)
{
NSString *text2;
NSString *currentString = textField.text;
NSString *newString = [text2 substringToIndex:[text2 length]-1];
textField.text=newString;
}
return NO;
}
return YES;
}