我有一个UItextfield
自动根据预先定义的字符串完成其值。如果第一个字符串currentString
中包含多个单词,则结果显示的最后一个字符为currentString
。附加到字符串的最后一个字母ByReplacingCharactersInRange
所以当输入No
,该UITextField
小号得到的文本变成Note todayt
(第二个字添加到字符串的最后一个字母)
- (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;
}
会向下选民关心解释为什么?如果你不能提出问题,这有什么意义呢? – JSA986