NSNumberFormatter 导致 iPhone SDK 4.0b2 崩溃
我有一个应用程序,它已经在应用程序商店中存在了一段时间,并且在操作系统 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 有变化吗?
谢谢,
豪伊
I've got an app that's been in the app store for a while and functions perfectly on OS 3.1 - 3.13. However, when tested on 4.0b2 I noticed that it crashes in the same place every time, but only on the device, never on the simulator. I'm using a 3GS to test.
On loadView I initialize an NSNumberFormatter object which is declared and retained in the interface so I have access to it everywhere. In my method I call it several times to convert string values into nsnumbers to be stored in a mutable dictionary.
Here's an example:
[myDictionary setObject:[myStyleFormatter numberFromString:@"1"] forKey:@"hours"];
[myDictionary setObject:[myStyleFormatter numberFromString:@"30"] forKey:@"minutes"];
[myDictionary setObject:[myStyleFormatter numberFromString:@"10"] forKey:@"seconds"];
For some reason it crashes as soon as it tries to set hours. The error is "attempt to insert nil value (key: hours)"
Have I been doing something wrong all along? Has the api changed for 4.0b2?
Thanks,
Howie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的问题。我追踪到一个
NSNumberFormatter
语句,该语句不喜欢数字中每 3 位数字有一个空格(或逗号)。这是使用数字格式化程序
的原因之一。在互联网上的许多示例中,这是相当标准的代码,因此我怀疑很多人都会发现问题。
无论如何,我通过删除空格来修复它
然后
currencyFormatter
行起作用了。但是,在我的代码的另一个区域中,相同的
currencyFormatter
语句没有任何问题。我尝试更改该区域的代码来导致问题,但我做不到。所以,非常好奇!!!
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 anumber formatter
.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
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!!!