xcode '+[NSInvocation invocationWithMethodSignature:]: 方法签名参数不能为 nil' (Cocos2D)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4473609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil' (Cocos2D)
提问by Thromordyn
Xcode 3.2.5, iOS 4.2 (Simulator), Cocos2D 0.99.5
Xcode 3.2.5、iOS 4.2(模拟器)、Cocos2D 0.99.5
Following this tutorialcomes with a wonderful crash, as seen below.
遵循本教程会带来精彩的崩溃,如下所示。
I haven't found a single (directly) relevant thing through Google on any site. The closest I got was something else on this site with the same error, but a completely different reason. (I assume so, anyway. But then, given that 0.99.5 comes with two Analyzer results, it could just be a bad release…)
我还没有在任何网站上通过 Google 找到任何(直接)相关的内容。我得到的最接近的是这个网站上的其他东西,有同样的错误,但完全不同的原因。(无论如何,我认为是这样。但是,鉴于 0.99.5 带有两个分析器结果,它可能只是一个糟糕的版本......)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil'
*** Call stack at first throw:
(
0 CoreFoundation 0x013cbbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x015205c2 objc_exception_throw + 47
2 CoreFoundation 0x0133bb09 +[NSInvocation invocationWithMethodSignature:] + 553
3 FirstGame 0x0005ddd4 -[CCMenuItem initWithTarget:selector:] + 308
4 FirstGame 0x0005e528 -[CCMenuItemLabel initWithLabel:target:selector:] + 104
5 FirstGame 0x0005fb1d -[CCMenuItemFont initFromString:target:selector:] + 365
6 FirstGame 0x0005f8db +[CCMenuItemFont itemFromString:target:selector:] + 123
7 FirstGame 0x00003457 -[HelloWorld init] + 231
8 FirstGame 0x00063db1 +[CCNode node] + 81
9 FirstGame 0x0000332d +[HelloWorld scene] + 93
10 FirstGame 0x00002dbc -[FirstGameAppDelegate applicationDidFinishLaunching:] + 1212
11 UIKit 0x0085a253 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1252
12 UIKit 0x0085c55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
13 UIKit 0x00866db2 -[UIApplication handleEvent:withNewEvent:] + 1533
14 UIKit 0x0085f202 -[UIApplication sendEvent:] + 71
15 UIKit 0x00864732 _UIApplicationHandleEvent + 7576
16 GraphicsServices 0x02973a36 PurpleEventCallback + 1550
17 CoreFoundation 0x013ad064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
18 CoreFoundation 0x0130d6f7 __CFRunLoopDoSource1 + 215
19 CoreFoundation 0x0130a983 __CFRunLoopRun + 979
20 CoreFoundation 0x0130a240 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x0130a161 CFRunLoopRunInMode + 97
22 UIKit 0x0085bfa8 -[UIApplication _run] + 636
23 UIKit 0x0086842e UIApplicationMain + 1160
24 FirstGame 0x000028a4 main + 100
25 FirstGame 0x00002835 start + 53
)
I can't come up with anything. Maybe someone else has seen this before?
我想不出什么。也许其他人以前见过这个?
回答by Marek Maurizio
I had the same error due to my poor knowledge of selectors in Objective-C. I initially implemented the goToGameplay method with the signature:
由于我对 Objective-C 中的选择器了解不足,我遇到了同样的错误。我最初使用签名实现了 goToGameplay 方法:
-(void)goToGameplay;
instead i had to use:
相反,我不得不使用:
-(void)goToGameplay:(id)sender;
This works with the call:
这适用于调用:
@selector(goToGameplay:)
Hope i helps.
希望我有所帮助。
回答by bbum
Specifically, it looks like this call?
具体来说,看起来像这个调用?
CCMenuItem *Play = [CCMenuItemFont itemFromString:@"PLAY" target:self selector:@selector(goToGameplay:)];
Have you implemented goToGameplay:
on your HelloWorld
class?
你goToGameplay:
在HelloWorld
课堂上实施了吗?
The way the tutorial is written, you don't write the method until later in the tutorial. Thus, if you run the tutorial in the middle and try to hit that menu item, it will crash as described above.
按照本教程的编写方式,您要在本教程的后面部分才编写方法。因此,如果您在中间运行教程并尝试点击该菜单项,它将如上所述崩溃。
回答by Justin Spahr-Summers
It looks like the selector you've passed to +[CCMenuItemFont itemFromString:target:selector:]
is not implemented on your target object. Trying to look up the selector would result in a nil
method signature, which would cause the error seen there.
看起来您传递给的选择器+[CCMenuItemFont itemFromString:target:selector:]
没有在您的目标对象上实现。尝试查找选择器会导致nil
方法签名,这将导致在那里看到错误。
回答by KenM
I had the same problem. My issue was in the PauseScene.m file creating the menu items for resume and quit. In my case one of the names in the @selector part of CCMenuItem did not match the method name used later. Specifically, for me I used @selector(GotoMainMenu) but used GoToMainMenu for the method...the difference was "To" vs "to". To check, put an NSLog at the top of the init in the PauseScene.m file. If you see the message, the problem is somewhere here. If not, it's probably earlier.
我有同样的问题。我的问题是在 PauseScene.m 文件中创建了用于恢复和退出的菜单项。就我而言,CCMenuItem 的 @selector 部分中的名称之一与后来使用的方法名称不匹配。具体来说,对我来说,我使用了 @selector(GotoMainMenu) 但在方法中使用了 GoToMainMenu ……区别在于“To”与“to”。要检查,请在 PauseScene.m 文件中的 init 顶部放置一个 NSLog。如果您看到该消息,则问题出在此处。如果没有,可能会更早。