objective-c - Xcode 错误 kCFNumberFormatterCurrencyStyle
问题描述
我正在尝试在地图上显示属性的应用程序中格式化 123,123 美元的美国货币。数字 show $(null) 应该显示 #
使用类型为“NSInteger”(又名“long”)的表达式初始化“NSInteger *”(又名“long *”)的不兼容整数到指针转换
从枚举类型'enum CFNumberFormatterStyle'到不同枚举类型'NSNumberFormatterStyle'的隐式转换(又名'enum NSNumberFormatterStyle')
cell.imgViewPropertyType.image = [UIImage imageNamed:@"for_sale"];
NSInteger *intPrice = [theProperty.priceSale integerValue];
NSNumber *tempPrice = [NSNumber numberWithInteger:intPrice];
NSString *price = [NSNumberFormatter localizedStringFromNumber:tempPrice numberStyle:kCFNumberFormatterCurrencyStyle];
解决方案
试试这个。请注意,这intPrice
不是指针,因此您需要声明为NSInteger intPrice
而不是NSInteger *intPrice
. 这就是您遇到错误的原因。
cell.imgViewPropertyType.image = [UIImage imageNamed:@"for_sale"];
NSInteger intPrice = [theProperty.priceSale integerValue];
NSNumber *tempPrice = [NSNumber numberWithInteger:intPrice];
正如 rmaddy 在下面指出的那样,您也可以使用下面的行。
NSNumber *tempPrice = @(intPrice);
关于关于CFNumberFormatterStyle
,localizedStringFromNumber
接受NSNumberFormatterStyle
而不是类型的第二个错误CFNumberFormatterStyle
。您正试图在那里传递错误类型的样式。尝试使用NSNumberFormatterCurrencyStyle
.
NSString *price = [NSNumberFormatter localizedStringFromNumber:tempPrice numberStyle:NSNumberFormatterCurrencyStyle];
推荐阅读
- r - 使用 R 在 Elasticsearch 中索引数据时出错
- ios - 如何在没有越狱设备的情况下测试越狱措施是否有效
- java - 在调度程序中捕获 Throwable 是一种好习惯吗?
- c# - 请解释这个转换扩展方法
- influxdb - 删除数据库的保留策略,默认为 true。在这种情况下,数据库保留策略会发生什么变化?
- php - Codeigniter 从数据库返回 Null 一个不为空的字段
- amazon-web-services - 我们可以知道 AWS EBS 卷的分离日期吗?
- javascript - 使用 Selenium 打开网页的问题
- python - 分组数据特征 - Pandas Python
- ffmpeg - FFMPEG:使用 Zoompan drawtext 抖动问题