开发者

Objective c - variable to label

开发者 https://www.devze.com 2023-02-28 05:47 出处:网络
Is a little problem 开发者_运维技巧with save int variable to label. int i = idpole; [lid2 setText:@\"%i\", i];

Is a little problem 开发者_运维技巧with save int variable to label.

int i = idpole;
[lid2 setText:@"%i", i]; 

Thats bad, but i tried more thing... i cant set this "settext:i", because this doesnt work. I try found something on google, but without sense.


use

int i = idpole;
[lid2 setText:[NSString stringWithFormat:@"%i", i]]; 


The text property of label is a NSString, so you can not set an integer directly. You need to convert that int to a string. You can use any of the followings:

lid2.text = [NSString stringWithFormat:@"%i", idpole]; // no need of temporary i
// or
[lid2 setText:[NSString stringWithFormat:@"%i", idpole]];


int i = idpole;
[lid2 setText:[NSString stringWithFormat:@"%d",i]];
0

精彩评论

暂无评论...
验证码 换一张
取 消