iPhone NSNumberFormatter 设置格式:
它看起来像是用于设置自定义格式化程序的NSNumberFormatter
方法。 setFormat:
在 iPhone 上不可用...
所以这...导致我的应用程序崩溃:
NSNumberFormatter *lengthFormatter = [[NSNumberFormatter alloc] init];
[lengthFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[lengthFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[lengthFormatter setFormat:@"#,##0.0M"];
其他人也遇到过这种情况吗?
谢谢,
丹 **答案如下。 NSNumberFormatter
还有名为 setPositiveFormat: setNegativeFormat:
的方法,它取代了已弃用的 setFormat:
**
It appears as though NSNumberFormatter's
method for setting custom formatters
. setFormat:
isn't available on the iPhone...
SO this... crashes my app:
NSNumberFormatter *lengthFormatter = [[NSNumberFormatter alloc] init];
[lengthFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[lengthFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[lengthFormatter setFormat:@"#,##0.0M"];
Has this occurred to anyone else?
Thanks,
Dan
**ANSWERED BELOW. NSNumberFormatter
also has methods called setPositiveFormat: setNegativeFormat:
which replace the depreciated setFormat:
**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,它在 NSNumberFormatter 类参考(需要登录)。 注释中写道:
编辑:添加了更多文本来支持后续问题。
您可以将您的文本重写为类似的内容:
我建议查看我上面链接的文档。 它是专门针对 iPhone 版本的 NSNumberFormatter 的,因此其中没有任何会导致应用程序崩溃的方法。 与原始 NSNumberFormatter 相比,它还旨在更多地利用用户的本地化设置。 有多种方法可以限制显示的内容等,同时仍然利用用户的偏好。 不幸的是,不再有
setFormat:
方法。Yes, it's documented as a note in the NSNumberFormatter Class Reference (requires login). The note says:
EDIT: Added more text to support follow-up questions.
You could re-write yours to something similar:
I suggest taking a look at the document that I linked above. It's specifically for the iPhone version of NSNumberFormatter, so none of the methods that will cause your application to crash are in there. It's also designed to take far more advantage of the user's localized settings than the original NSNumberFormatter did. There are groups of methods for restricting what shows up and such while still taking advantage of the user's preferences. Unfortunately, there is no longer a
setFormat:
method.