开发者

NSBundle argument in a method call

I have to call this method:

[super initWithPNGFileName: "/Volumes/SAGITTER/Lavoro/Progetti xCode/IVBricker test/ball.png" andGame:game andCGRect:CGRectMake(x,y,16,16)];

So when I put this on the iPhone, the path is not right. I know I must use NSBundle but if I do

[super initWithPNGFileName:[[NSBundle mainBundle] pathForResource:@"ball" ofType:@"png" inDirectory:@"/"] andGame:game andCGRect:CGRectMake(x,y,16,16)];
开发者_如何学C

I get the alert: "passing argument 1 of 'initWithPNGFileName:andGame:andCGRect:' from incompatible pointer type"

How should I proceed using NSBundle?


if [super initWithPNGFileName: "/Volum... is 100% correct code I think this message expects a C-Style string.
But [[NSBundle mainBundle] pathForResource:...] will return a NSString object.

Try to pass [[[NSBundle mainBundle] pathForResource:@"ball" ofType:@"png" inDirectory:@"/"] cStringUsingEncoding:NSUTF8StringEncoding] to the method.


Your 1st call passes c-string to initWithPNGFileName: method, while -pathForResource: returns NSString. Get c-string from the path you get from bundle and pass that string to your method:

[super initWithPNGFileName:[[[NSBundle mainBundle] pathForResource:@"ball" ofType:@"png" inDirectory:@"/"] UTF8String]
                   andGame:game 
                 andCGRect:CGRectMake(x,y,16,16)];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜