@selector - With Multiple Arguments?

前端 未结 9 742
刺人心
刺人心 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 02:59

    I had an issue where I needed to use the afterDelay along with multiple arguments to my @selector method. Solution? Use a wrapper function!

    Say this is the function I want to pass to @selector:

    -(void)myFunct:(NSString *)arg1 andArg:(NSString *)arg2 andYetAnotherArg:(NSString *)arg3;
    

    Obviously, I can't even use withObject: withObject: here, so, make a wrapper!

    -(void)myFunctWrapper:(NSArray *)myArgs {
        [self myFunct:[myArgs objectAtIndex:0] andArg:[myArgs objectAtIndex:1] andYetAnotherArg:[myArgs objectAtIndex:2]];
    }
    

    and use it by doing:

    NSArray *argArray = [NSArray arrayWithObjects:string1,string2,string3,nil];
    [self performSelector:@selector(myFunctWrapper:) withObject:argArray afterDelay:1.0];
    

    This way I can have multiple arguments and use the selector with delay.

提交回复
热议问题