簡體   English   中英

如何在Objective-C的NSNumber后面附加一個字符?

[英]How to append a char to NSNumber in Objective-C?

我有一個來自API price: 10的價格參數price: 10我想在文本字段中顯示它,並在其后附加“ $”。 但這即使顯示也不會顯示我的電話號碼。 這是我的代碼:

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

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

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

NSNumber是一個對象,使用%i格式將無法正常工作。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM