本帖最后由 nsswift 于 2015-6-13 17:31 编辑
- //无参数
- -(void)noParam;
- //一个参数
- -(void)oneParam:(NSString *)oneParam;
- //两个参数
- -(void)oneParam:(NSString *)oneParam twoParam:(NSString*)twoParam;
- //最多支持两个参数
- [TestClass performSelector:@selector(noParam)];
- [TestClass performSelector:@selector(oneParam:)withObject:@"参数1"];
- [TestClass performSelector:@selector(oneParam:twoParam:)withObject:@"参数1" withObject:@"参数2"];
- //多参数
- //最多只能支持两个参数,因此多参数只能别想办法
- //比如将参数放在数组中,然后使用一个参数的使用方法可以实现
复制代码
SEL: @selector() 可以先赋值
- SEL s1 = @selector(test1);
- SEL s2 = NSSelectorFromString(@"test2");//通过NSString定义SEL
- [Test performSelector:s1];
- NSString *str = NSStringFromSelector(s1); //这样str=@“test1”;SEL转string;
复制代码
|
|