任何人都可以清楚地解释(带有示例)为什么我们必须将动态分配指针的数据类型从默认的void类型更改为其相应指针变量的相同数据类型?
例如:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
int groupingSize = 2;
if([string length] == 0) {
groupingSize = 4;
}
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init] ;
NSString *separator = @"-";
[formatter setGroupingSeparator:separator];
[formatter setGroupingSize:groupingSize];
[formatter setUsesGroupingSeparator:YES];
[formatter setSecondaryGroupingSize:2];
if (![string isEqual: @""] && (textField.text != nil && textField.text.length > 0)) {
NSString *num = textField.text;
num = [num stringByReplacingOccurrencesOfString:separator withString:@""];
NSString *str = [formatter stringFromNumber:[NSNumber numberWithDouble:[num doubleValue]]];
textField.text = str;
}
return YES;
}