@selector - With Multiple Arguments?

前端 未结 9 741
刺人心
刺人心 2020-12-13 02:26

I have been using @selector today for the first time and have not been able to work out how to do the following? How would you write the @selector

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 03:09

    Using NSInvocation as you specify you can create an NSObject category that implements

    - (void)performSelector:(SEL)aSelector withObjects:(NSArray *)arguments;
    

    Something like:

    - (void)performSelector:(SEL)aSelector withObjects:(NSArray *)arguments
    {
        NSMethodSignature *signature = [self methodSignatureForSelector: aSelector];
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature];
        [invocation setSelector: aSelector];
    
        int index = 2; //
        for (NSObject *argument in arguments) {
            [invocation setArgument: &argument atIndex: index];
            index ++;
        }
        [invocation invokeWithTarget: self];
    }
    

    from: iOS - How to implement a performSelector with multiple arguments and with afterDelay?

提交回复
热议问题