NSNumber正在模拟器中无法在iPad中工作

时间:2014-08-05 16:47:21

标签: ios ipad nsnumber

我正在将文本转换为NSNumber,并且它在iPad模拟器中正常工作,而它在真正的iPad设备中运行(null)。请问我的问题在哪里?

NSNumberFormatter * f = [[NSNumberFormatter alloc] init];

[f setNumberStyle:NSNumberFormatterDecimalStyle];

NSNumber * myNumber1 = [f numberFromString:[self txtValue1].text];
NSNumber * myNumber2 = [f numberFromString:[dic objectForKey:from?@"in":@"out"]];

float result1 = [myNumber1 floatValue];
float result2 = [myNumber2 floatValue];

NSLog(@"Check the value2 %@ ",myNumber1); //Result (null)
NSLog(@"Check the value3 %f ", result1); //Result "0"

NSLog(@"string1: %@", [self txtValue1].text); //result in iPad device: 1.35
NSLog(@"string2: %@", [dic objectForKey:from?@"in":@"out"]) //result in iPad device: 1.2

NSLog(@"string1: %@", [self txtValue1].text); //result in iPad Simulator: 1.35
NSLog(@"string2: %@", [dic objectForKey:from?@"in":@"out"]) //result in iPad Simulator: 1.2

1 个答案:

答案 0 :(得分:0)

我已将NSNumber的代码类型更改为@ -notation类型,而不是NSNumberFormatter,如本主题NSNumber @-notation中所述,最后它开始显示值iPad设备。

NSNumber * myNumber1 = @([[self txtValue1].text floatValue]);
NSNumber * myNumber2 = @([[dic objectForKey:from?@"in":@"out"] floatValue]);

float result1 = [myNumber1 floatValue];
float result2 = [myNumber2 floatValue];

NSLog(@"Check the value2 %@ ",myNumber1); //Result 1.35 which it should be
NSLog(@"Check the value3 %f ", result1); //Result 1.2 which it should be