Home > DeveloperSection > Forums > @selector creation with method name and parameter
Steven Hill
Steven Hill

Total Post:10

Posted on    November-09-2015 2:58 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 293  View(s)
Rate this:

I created a sample that gets a SEL from currentObject,
SEL callback = @selector(methodName: parameterTwo);
Andalso I have a method like this:

- (void) methodName: (id) var1 parameter2;(NSString*) var2 {

Now I want to move methodName to another object, with passing delegateObj.
This is the code that I have tried:

SEL callback = @selector(myDelegate, mymethod:parameter2);

but it’s not working, please anyone tell me the reason.

Tarun Kumar

Total Post:210

Posted on    November-15-2015 10:47 PM

It looks like you are  trying to implement a callback. The best way to do is something like this:

[object setCallbackObject:self withSelector:@selector(myMethod:)];

We can not pass parameter's in a @ selector().
Then in our object's setCallbackObject:withSelector: method: we can call your callback method.

-(void)setCallbackObject:(id)anObject withSelector:(SEL)selector {
    [anObject performSelector:selector];

Don't want to miss updates? Please click the below button!

Follow MindStick