1

我有一个应用程序已经在应用程序商店中出现了一段时间,并且在 OS 3.1 - 3.13 上完美运行。但是,在 4.0b2 上进行测试时,我注意到它每次都在同一个地方崩溃,但只在设备上,从不在模拟器上。我正在使用3GS进行测试。

在 loadView 上,我初始化了一个 NSNumberFormatter 对象,该对象在接口中声明并保留,因此我可以在任何地方访问它。在我的方法中,我多次调用它来将字符串值转换为 nsnumbers 以存储在可变字典中。

这是一个例子:

[myDictionary setObject:[myStyleFormatter numberFromString:@"1"] forKey:@"hours"];
[myDictionary setObject:[myStyleFormatter numberFromString:@"30"] forKey:@"minutes"];
[myDictionary setObject:[myStyleFormatter numberFromString:@"10"] forKey:@"seconds"];

出于某种原因,它会在尝试设置小时数时立即崩溃。错误是“尝试插入零值(键:小时)”

我是不是一直做错事?4.0b2 的 api 是否已更改?

谢谢,

豪伊

4

1 回答 1

1

I had the same problem. I tracked it down to a NSNumberFormatter statement that did not like spaces (or commas) every 3 digits in the numbers. Which is one of the reasons for having a number formatter.

NSNumber *number = [currencyFormatter numberFromString:mstring];

It is fairly standard code in many examples on the internet, so I suspect a lot will find the problem.

Anyway, I fixed it by getting rid of the spaces

NSArray *sArray = [mstring componentsSeparatedByString:@" "];
[mstring setString:@" "]; //space at beginning is OK, would prefer nil
for (NSString *sElement in sArray) {
    [mstring appendString:sElement];
}

Then the currencyFormatter line worked.

BUT, in another area of my code, that same currencyFormatter statement worked with no problem. I tried changing code in the area to cause the problem, but I could not.

So, very curious!!!

于 2010-07-09T18:47:06.093 回答