如何在Objective-C中将char添加到NSNumber?

问题描述 投票:1回答:2

我有一个来自我的API price: 10的价格参数我想在我的文本字段中显示它并在其后附加“$”。但即使投下它也无法显示我的号码。这是我的代码:

cell.price.text = [[NSString stringWithFormat:@"%i",
(NSNumber*)DIC[@"items"][indexPath.row][@"price"]] stringByAppendingString:@" $"];
ios objective-c casting nsstring string-formatting
2个回答
4
投票

要打印NSNumber,您需要使用%@而不是%i

cell.price.text = [NSString stringWithFormat:@"%@ $",
(NSNumber*)DIC[@"items"][indexPath.row][@"price"]];

2
投票

NSNumber是一个对象,使用格式%我将无法正常工作。

cell.price.text = [NSString stringWithFormat:@"%@ $",
(NSNumber*)DIC[@"items"][indexPath.row][@"price"]];
© www.soinside.com 2019 - 2024. All rights reserved.