- NSInvacation可以傳入任意多的參數(shù),而performSelector: withObject:最多只能傳入2個(gè)參數(shù).
- 1.調(diào)用方法
//調(diào)用哪個(gè)類的方法就用哪個(gè)類:ViewController
NSMethodSignature * signture = [ViewController instanceMethodSignatureForSelector:@selector(test)];
NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:signture];
invocation.target = self;
invocation.selector = @selector(test);
NSString * name = @"測(cè)試";
//0和1 都被系統(tǒng)的占用了 self 和 _cmd占用
[invocation setArgument:&name atIndex:2];
[invocation invoke];
// NSInvocationOperation * opt = [[NSInvocationOperation alloc] initWithInvocation:invocation];
- (void)test:(NSString *)name
{
NSLog(@"---%@",name);
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者