zoukankan      html  css  js  c++  java
  • performSelector支持多参数

    默认的performSelector支持最多传递两个参数,要想传递超过两个的参数,需要使用NSInvocation来模拟performSelector的行为,如下:

    - (id)performSelector:(SEL)aSelector withObjects:(NSArray *)argumentsArray

    {

        NSMethodSignature *sig = [selfmethodSignatureForSelector:aSelector];

        if (sig)

        {

            NSInvocation *invocation = [NSInvocationinvocationWithMethodSignature:sig];

            [invocation setTarget:self];

            [invocation setSelector:aSelector];

            

            for (int i = 0; i < argumentsArray.count ; ++i)

            {

                id argument = [argumentsArray objectAtIndex:i];

                //此处+2不能漏

                [invocation setArgument:&argument atIndex:i + 2];

            }

            

            [invocation invoke];

            if (sig.methodReturnLength)

            {

                id anObject = nil;

                [invocation getReturnValue:anObject];

                return anObject;

            }

            

            return nil;

        }

        

        returnnil;

    }

  • 相关阅读:
    android-sdk环境变量配置
    2018/08/04
    python 读取配置文件ini ---ConfigParser
    关于自动化测试框架搭建的前期考虑问题
    Jmeter中用例禁用
    Jmeter创建一个http请求
    基本的sql语法
    sql创建表格时出现乱码
    Jmeter安装
    Java环境搭建
  • 原文地址:https://www.cnblogs.com/lexingyu/p/3387323.html
Copyright © 2011-2022 走看看