因此,当用户输入生日时,我尝试在 2 位数字之间自动添加斜杠,但由于某种原因,当生日以 0 开头时,数字格式化程序会删除它并弄乱生日。我的代码在下面,有人可以帮我弄清楚如何做到这一点吗?提前致谢!
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init] ;
[formatter setGroupingSeparator:@"/"];
[formatter setGroupingSize:2];
[formatter setUsesGroupingSeparator:YES];
[formatter setSecondaryGroupingSize:2];
NSString *num = textField.text ;
if(![num isEqualToString:@""])
{
num= [num stringByReplacingOccurrencesOfString:@"/" withString:@""];
NSString *str = [formatter stringFromNumber:[NSNumber numberWithDouble:[num doubleValue]]];
textField.text=str;
}