zoukankan      html  css  js  c++  java
  • iOS的反射机制之方法调用

    在ViewController载入的时候,生成并添加Invocation

    [self  addInvocation:WebServcieAddressTextselector:@selector(invokeTest)];

     

    -(void)addInvocation:(NSString*)title selector:(SEL)selector{

        

        NSMethodSignature *methodSignature = [[selfclassinstanceMethodSignatureForSelector: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];

    }

     

  • 相关阅读:
    KVM 重命名虚机
    甲醛了解
    递归函数,匿名函数
    函数
    zabbix监控URL
    zabbix自动发现
    vim常用命令总结
    saltstack常用命令
    zabbix监控Apache
    nginx配置详解
  • 原文地址:https://www.cnblogs.com/taojigu/p/2913719.html
Copyright © 2011-2022 走看看