how can i pass an int value through a selector method?

后端 未结 3 1797
孤城傲影
孤城傲影 2020-12-15 09:34

I want to pass an int value from my selector method, but the selector method takes only an object type parameter.

int y =0;
[self performselecto         


        
3条回答
  •  独厮守ぢ
    2020-12-15 10:09

    This works also for an int parameter, which is especially useful, if you are unable to change the signature of the selector you want to perform.

    SEL sel = @selector(tabledata:);
    
    NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:sel];
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
    invocation.selector = sel;
    // note that the first argument has index 2!
    [invocation setArgument:&y atIndex:2];
    
    // with delay
    [invocation performSelector:@selector(invokeWithTarget:) withObject:self afterDelay:0.1];
    

提交回复
热议问题