一,方法中写多个参数调用
- (void)test1 {
[self testFunctionWithParams1:6 :@"234131#"];
}
- (void)testFunctionWithParams1:(int )number :(NSString *)string {
NSLog(@"方法多个参数:%i%@",number, string);
}
二,performSelector调用方法
#pragma mark - 2,performSelector传参数:最多两个参数
- (void)test2 {
[self performSelector:@selector(testFunctionWithParams1::) withObject:@5 withObject:@"67"];
// 动态加载方法:需要对指针做处理,最多两个参数
// SEL selector = NSSelectorFromString(@"testFunctionWithParams2::");
// IMP imp = [self methodForSelector:selector];
// void (*func)(id, SEL) = (void *)imp;
// if([self respondsToSelector:selector]){
// func(self,selector);
// };
// 也可以采用延时,但只能传一个参数
// SEL selector = NSSelectorFromString(@"testFunctionWithParams2:");
// [self performSelector:selector withObject:@"tom" afterDelay:0.1f];
}
- (void)testFunctionWithParams:(NSString *)string {
NSLog(@"performSelector传参数:%@", string);
}
- (void)testFunctionWithParams2:(int )number :(NSString *)string {
NSLog(@"performSelector传参数:%i%@",number, string);
}
三,传字典,封装成对象
#pragma mark - 3,传字典
- (void)test3 {
//封装参数
NSDictionary *dic = @{@"param1":@"this is a string",@"param2":@[@2,@3,@3],@"param3":@123};
//调用方法
[self testFunctionWithParams3:dic];
}
- (void)testFunctionWithParams3:(NSDictionary *)paramDic {
NSLog(@"传字典:%@", paramDic);