[英]Terminating app due to uncaught exception 'NSInvalidArgumentException
Ok here is an interesting one... I am receiving the warning: Characters may not respond to 'addHeroType:atX:atY:fromMobTable'
好的,这是一个有趣的事件...我收到警告: Characters may not respond to 'addHeroType:atX:atY:fromMobTable'
although I have the functions defined properly as far as I can see so how about another pair of eyes? 虽然据我所知,我已经正确定义了功能,但是另一双眼睛呢?
Here is the definition in Characters.h
这是Characters.h
的定义
-(void) addHeroType:(int)newMobType atX:(int)x atY:(int)y fromMobTable:(Mobdefs*)newMobTable;
Here is the function in the Characters.m
这是Characters.m
的函数
-(void) addHeroType:(int)newMobType atX:(int)x atY:(int)y fromMobTable:(Mobdefs*)newMobTable
and here is the call I am making in another class call heroFactory ( Characters.h
is included in heroFactory): 这里是我在另一个类调用heroFactory(进行调用Characters.h
包括在heroFactory):
[Characters addHeroType:1 atX:location.x atY:location.y fromMobTable:newMobTable];
But this line causes the app to terminate due to uncaught exception - checking the debugger I see "NSObject Does Not Recognize Selector" 但是此行导致应用程序由于未捕获的异常而终止-检查调试器,我看到“ NSObject无法识别选择器”
I am convinced that the issue is the wierdness of why I am seeing a warning that the Character class may not respond to the function call as written even though it matches identically to the definition. 我确信,问题出在为什么我看到一个警告,即即使Character类与定义完全匹配,它也可能无法响应编写的函数调用,这令人感到困惑。
Any help greatly appreciated. 任何帮助,不胜感激。
-(void) addHeroType:(int)newMobType atX:(int)x atY:(int)y fromMobTable:(Mobdefs*) newMobTable
That is declared as an instance method. 声明为实例方法。
[Characters addHeroType:1 atX:location.x atY:location.y fromMobTable:newMobTable];
But you are calling it on the class as a class method. 但是您在类上将其作为类方法调用。
So either, declare the method as a class method 因此,要么将方法声明为类方法
+(void) addHeroType:(int)newMobType atX:(int)x atY:(int)y fromMobTable:(Mobdefs*) newMobTable
Or call it on an instance 或在实例上调用
Characters *instance = [[[Characters alloc] init] autorelease];
[instance addHeroType:1 atX:location.x atY:location.y fromMobTable:newMobTable];
Depending on the scope your method requires, of course. 当然,取决于您的方法要求的范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.