简体   繁体   中英

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'

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

-(void) addHeroType:(int)newMobType atX:(int)x atY:(int)y fromMobTable:(Mobdefs*)newMobTable;

Here is the function in the 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):

[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"

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM