0

我必须调用这个方法:

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

所以当我把这个放到 iPhone 上的时候,路径不对。我知道我必须使用 NSBundle 但如果我这样做

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

我收到警报:“从不兼容的指针类型传递 'initWithPNGFileName:andGame:andCGRect:' 的参数 1”

我应该如何继续使用 NSBundle?

4

2 回答 2

0

您的第一次调用将 c-string 传递给initWithPNGFileName:方法,同时-pathForResource:返回 NSString。从您从 bundle 获得的路径中获取 c-string 并将该字符串传递给您的方法:

[super initWithPNGFileName:[[[NSBundle mainBundle] pathForResource:@"ball" ofType:@"png" inDirectory:@"/"] UTF8String]
                   andGame:game 
                 andCGRect:CGRectMake(x,y,16,16)];
于 2011-03-02T10:05:55.480 回答
0

如果[super initWithPNGFileName: "/Volum...是 100% 正确的代码我认为这条消息需要一个 C 风格的字符串。
[[NSBundle mainBundle] pathForResource:...]会返回一个 NSString 对象。

尝试传递[[[NSBundle mainBundle] pathForResource:@"ball" ofType:@"png" inDirectory:@"/"] cStringUsingEncoding:NSUTF8StringEncoding]给方法。

于 2011-03-02T10:06:35.370 回答