Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 方法调用中的NSBundle参数_Objective C_Path_Nsbundle - Fatal编程技术网

Objective c 方法调用中的NSBundle参数

Objective c 方法调用中的NSBundle参数,objective-c,path,nsbundle,Objective C,Path,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 mainBund

我必须调用此方法:

[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)];
我收到警告:“正在传递参数1'initWithPNGFileName:andGame:andCGRect:'来自不兼容的指针类型”


如何继续使用NSBundle?

您的第一次调用将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)];

如果
[super initWithPNGFileName:“/volume…
是100%正确的代码,我认为此消息需要C样式的字符串。
但是
[[NSBundle mainBundle]pathForResource:…]
将返回一个NSString对象

尝试将
[[NSBundle mainBundle]pathForResource:@“png”类型的@“ball”在目录中:@/“]cStringUsingEncoding:NSUTF8StringEncoding]
传递给该方法