开发者

NSString Formatting Issue

开发者 https://www.devze.com 2023-03-02 02:06 出处:网络
I am having some trouble formatting an NSString So i have and NSString and an Int I want to use them to set an Image in a IUImage View, here is my code

I am having some trouble formatting an NSString

So i have and NSString and an Int

I want to use them to set an Image in a IUImage View, here is my code

headOnString = @"test";
slideNumber = 0;
NSLog(@"%@%i.png",headOnString, slideNumber);
photoDisplay.image = [UIImage imageNamed:(@"%@%i.png", headOnString, slideNumber)];

the goal is for this is to read [UIImage imageNamed:@"test0.png"];

im getting an "expression result unused for the "headOnString" string and an "incompatible pointer conversion sending int 开发者_如何学Cto NSString"

I always have trouble with string formatting. Any suggestions would be greatly appreciated. Thanks.


use this:

photoDisplay.image = [UIImage imageNamed: [NSString stringWithFormat:@"%@%i.png", headOnString, slideNumber]];

and take care that the format fits the type of the variables, you can easily crash by using wrong format for your variables.

0

精彩评论

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