Creating a selector from a method name with parameters

前端 未结 3 671
栀梦
栀梦 2020-11-28 19:32

I have a code sample that gets a SEL from the current object,

SEL callback = @selector(mymethod:parameter2);

And I have a met

3条回答
  •  忘掉有多难
    2020-11-28 20:10

    You can't pass a parameter in a @selector().

    It looks like you're trying to implement a callback. The best way to do that would be something like this:

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

    Then in your object's setCallbackObject:withSelector: method: you can call your callback method.

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

提交回复
热议问题