我遇到了一个问题,我正在跟踪用户输入的字符并且它工作正常,但是当用户删除文本字段中的整个消息并且文本字段变为空时,它给出文本字段文本长度 = 1。它应该是 0 ,我我没有得到这一切。任何帮助
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == textfield1)
{
NSLog(@"%d",textfield1.text.length);
NSInteger charleft = (100 - textfield1.text.length);
NSLog(@"The Characters left are %d",charleft);
while(!(charleft<0))
{
NSString *Charlength= [NSString stringWithFormat:@"%d",charleft];
Charcount.text= [ Charlength stringByAppendingFormat:@" Characters left"];
return YES;
}
return NO;
}