Reputation: 25
call method from the same class that looks like
-(void)functionA:(TemplateController *)sender ??
[self functionA];
but I am getting an error of instance method not found.Upvotes: 0
Views: 65
Reputation: 56
In your method -(void)functionA:(TemplateController *)sender
, sender is a parameter to the method.So when you call functionA
method you should specify the parameter even though parameter is nil
, ie [self functionA:nil]
. If you don't need any parameter to be passed you should change your method as -(void)functionA
, then you can call it as [self functionA]
.
Upvotes: 0
Reputation: 1221
I think you need to read about function syntax in objective-c
- (type_r) abc:(type1)x cde:(type2)y def:(type3)z
is an instance method (using it requires creation of an object) whose name is abc:cde:def:
, which returns something of type type_r, receives three arguments x, y and z, of types type1, type2 and type 3 respectively.
To call it, you say
class_name obj = [[class_name alloc] init];
[obj abc:x1 cde:y1 def:z1];
It is like doing this in c++:
class_name obj = new class_name();
obj.func_name(x1, y1, z1);
If there was a '+' instead of '-' at the beginning, this would mean it is a class method and it is supposed to be called using just the class name
[class_name abc:x1 cde:y1 def:z1];
Secondly, functions are not 'implemented' in header files. They are just 'declared' as a directive to the compiler that don't worry, you will find the implementation of this function at the linking time.
Upvotes: 0
Reputation: 5081
Your method has an Parameter.
-(void)functionA:(TemplateController *)sender
Paramter is TemplateController so without passing this parameter. this method not being called.
you are not passing the parameter so it gives an error.
[self FunctionA];
This is wrong way.
So pass the parameter Like this
[self functionA:templateControllerObject];
Upvotes: 0
Reputation: 46543
-(void)functionA:(TemplateController *)sender
Is a method named functionA:
, which expects a parameter of type TemplateController
While you are not passing any parameter to it [self functionA]
.
It should be something like this
[self functionA:templateControllerObject]
Upvotes: 2