我有以下代码:
long mins = 02; long secs = 35;
NSString *allTime = [[NSString alloc]init];
allTime = @"%i:%i",mins, secs ;
但它不起作用,因为当我尝试显示那个 nsstring 对象时,我得到了这个:%i:%i 而不是我想得到:02:35
怎么做? 谢谢!
allTime = [NSString stringWithFormat:@"%l/%l", mins, secs];
for(Playlists *thePL in collection)
{
NSLog(@"===NEXT PLAYLIST===");
NSLog(@"Name: %@", thePL.namePL);
NSLog(@"Quantity of songs: %i", thePL.entries);
NSLog(@"Total of time: %@",thePL.allTime);
}
总时间:l
最佳答案
您需要使用stringWithFormat
,参见NSString Class Reference
.
allTime = [NSString stringWithFormat:@"%d:%d",mins, secs];
关于objective-c - 如何将带有变量的 NSString 分配给 nsstring 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11420100/