0
我的标签,我想这其中的一个NSInteger的,另一串目标c如何将字符串值添加到整数?
_imgIndex.text = [@(index+1) stringValue]; //how to add string here?
我的标签,我想这其中的一个NSInteger的,另一串目标c如何将字符串值添加到整数?
_imgIndex.text = [@(index+1) stringValue]; //how to add string here?
看来,你有一个整数值(index
)和对象 - 字符串对象(给它两个元素的值stringValue
),并且你想连接它们。有许多这样做的方法,这里有两个:
_imgIndex.text = [NSString stringWithFormat:@"%lu%@",index,stringValue];
另一种技术是先将整数转换成字符串,然后拼接另一个字符串:
_imgIndex.text = [@(index).description stringByAppendingString:stringValue];
http://stackoverflow.com/questions/510269/shortcuts-in-objective-c-to-concatenate-nsstrings – luk2302