-1

My question is about a case where things work fine for a method with one parameter, but not for two. The code comes from Apple animation sample code.

the main view object, (self), has readonly reference to an abstract superclass object, s.

It can call methods on an instance that inherits from the superclass like this:

[self.s myMethod:param1];

and it works fine.

However, when I try:

[self.s anotherMethod:param1 secondParam:param2];

I get the compile error:

Semantic Issue > Instance method '-anotherMethod:secondParam:' not found (return type defaults to 'id')

Both the methods have return type - (void).

Everything is declared and defined in the same way for the first case and the second.

Any suggestions would be greatly appreciated.

(I don't really want to resort to bundling up parameters into a single object!)


amendment with example added below

declarations like this in .h files of superclass and inherited class

for the super class:

@interface SuperClass : NSObject
{
...
}
...
- (void) myMethod:(SomeObject *) param1;
- (void) anotherMethod:(SomeObject *) param1: (int) param2;
@end

for the inherited class:

#import "SuperClass.h"
@interface InheritedClass : SuperClass
{
...
}
...
- (void) myMethod:(SomeObject *) param1;
- (void) anotherMethod:(SomeObject *) param1: (int) param2;
@end

implementations in .m file of each class

have tried adding this to the inherited class .m file.

@interface InheritedClass ()
- (void) anotherMethod:(SomeObject *) param1: (int) param2;
@end
4

1 回答 1

1

这个电话:

[self.s anotherMethod:param1 secondParam:param2];

...表示方法名称是anotherMethod:secondParam:.

本声明:

- (void) anotherMethod:(SomeObject *) param1: (int) param2;

...没有相同的名称。

有没有可能你的意思是:

- (void) anotherMethod:(SomeObject *)param1 secondParam:(int)param2;

?

于 2012-07-10T05:53:02.613 回答