views:

55

answers:

4

Hello,

How do we call a method which is in classB from @selector tag of classA.??

Can i do it in this way??

[tis_obj authenticate:self action:@selector([classB method]:)
              accName:@"BOOK" User:@"User"];

Is there a possibility to call a method of different class form@selector tag?? or should the method be always in same class?

Thank You.

+3  A: 

No you can't. To call a -[classB method:], the authenticate: parameter must have a classB instance, e.g.

classB* b = [[clasB alloc] init];
[tis_obj authenticate:b action:@selector(method:) …];
self.b = b;
[b release];
KennyTM
+1  A: 

A selector is just a name. The selector in the method call [someObject foo:5] is just foo:. It doesn't specify a method or a receiver, just the name.

Chuck
+1  A: 

What you pass to @selector() doesn't have a class name. A selector definition is simply a method name, so this will work:

[tis_obj authenticate:self action:@selector(method:)
          accName:@"BOOK" User:@"User"];

(if "method:" is defined on your class of course)

Philippe Leybaert
+2  A: 

It looks like you want tis_obj to use the method selector on classB. I'm not sure what tis_obj is, but I see you're passing an argument self there. Perhaps what you're really looking for is:

[tis_obj authenticate:classB
               action:@selector(method:)
              accName:@"BOOK"
                 User:@"User"];

This will presumably mean that tis_obj will at one point perform the equivalent of [classB method:someArg].

dreamlax