[置顶] iOS 调用的多个参数的方法

SEL theSelector = @selector(yourMethodWithString:number:) 
NSMethodSignature * sig = [self methodSignatureForSelector:theSelector]; 
NSInvocation * theInvocation = [NSInvocation   
invocationWithMethodSignature:sig]; 
[theInvocation setTarget:self]; 
[theInvocation setSelector:theSelector]; 

NSString *firstArgument = [NSString stringWithString:@"Test"]; 
NSNumber *secondArgument = [NSNumber numberWithInt:2]; 
[theInvocation setArgument:&firstArgument atIndex:2]; 
[theInvocation setArgument:&secondArgument atIndex:3]; 
[theInvocation retainArguments];

selector 如何调用多个参数呢?

  1. NSArray和NSDictionary
NSArray *paramArray = [NSArrray arrayWithObjects:@"param1",@"param2",nil];
[self performSelector:@selector(printObjcets:) withObject:paramArray];
    3.
//#import <objc/message.h>
NSSelectorFromString(@"printStr:printNum:printName:"),@"a String",[NSNumber numberWithInt:6],@"test name");

你可能感兴趣的:(ios,多参数,selector)