Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将整数值绑定到标签中_Ios - Fatal编程技术网

Ios 将整数值绑定到标签中

Ios 将整数值绑定到标签中,ios,Ios,我必须绑定Json数据,字符串格式的数据在标签中绑定ok,但我不能在标签中绑定整数或浮点值。在标签中绑定这些类型的值是否有语法 NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys: showcost.text = [loans objectForKey:@"Cost"], showname.text = [loan

我必须绑定Json数据,字符串格式的数据在标签中绑定ok,但我不能在标签中绑定整数或浮点值。在标签中绑定这些类型的值是否有语法

        NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:

                      showcost.text = [loans objectForKey:@"Cost"],
                      showname.text =  [loans objectForKey:@"Name"],nil];

我得到了名字,但我不能约束成本,答案是12.34。请给我一个继续的想法。

如果成本是浮点型的,您可以使用stringWithFormat为其创建一个字符串值,将十进制浮点数打印为字符串:

showcost.text = [NSString stringWithFormat:@"%f", [loans objectForKey:@"Cost"]];

可以将字符串文字的属性用作

showcost.text =[NSString stringWithFormat:@"%f",[[loans objectForKey:@"Cost"]floatValue]];
对于整数值

int cost = [[loans objectForKey:@"Cost"]intValue];
showcost.text = [NSString stringWithFormat:@"%d",cost];
对于浮点值

float cost = [[loans objectForKey:@"Cost"]floatValue];
showcost.text = [NSString stringWithFormat:@"%f",cost];

如何通过代码或IB绑定到UILabel?您是否将其存储在字典中?Iam通过代码绑定并将其存储在字典中。此答案甚至无法编译,因为您试图将浮点值分配给NSString*类型的属性。您不应使用字符串格式向用户显示数字。相反,请使用NSNumberFormatter,以便根据用户的区域设置正确设置值的格式。