在ViewController载入的时候,生成并添加Invocation
[self addInvocation:WebServcieAddressTextselector:@selector(invokeTest)];
-(void)addInvocation:(NSString*)title selector:(SEL)selector{
NSMethodSignature *methodSignature = [[selfclass] instanceMethodSignatureForSelector:selector];//获得类和方法的签名
NSInvocation *invocation = [NSInvocationinvocationWithMethodSignature:methodSignature];
//从签名获得调用对象
[invocation setTarget:self];
invocation.target=self;
invocation.selector=selector;
[invocationArrayaddObject:invocation];
[titleArrayaddObject:title];
}
-(void)invokeTest{
NSLog(@"Test invoked");
}
点击UITableView中的某一行的时候,根据IndexPath读取出NSInvocation,并且执行。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInvocation*invc=[invocationArrayobjectAtIndex:indexPath.row];
[invc invoke];
}