方法调用中的 NSBundle 参数
我必须调用这个方法:
[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?
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)];
I get the alert: "passing argument 1 of 'initWithPNGFileName:andGame:andCGRect:' from incompatible pointer type"
How should I proceed using NSBundle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
if
[super initWithPNGFileName: "/Volum...
是 100% 正确的代码,我认为此消息需要 C 风格字符串。但是
[[NSBundle mainBundle] pathForResource:...]
将返回一个 NSString 对象。尝试将
[[[NSBundle mainBundle] pathForResource:@"ball" ofType:@"png" inDirectory:@"/"] cStringUsingEncoding:NSUTF8StringEncoding]
传递给该方法。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.您的第一个调用将 c 字符串传递给
initWithPNGFileName:
方法,而-pathForResource:
返回 NSString。从从捆绑包获得的路径中获取 c-string 并将该字符串传递给您的方法: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: