Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Objective-C运行时方法\u ExchangeImplements不起作用_Ios_Objective C_Runtime - Fatal编程技术网

Ios Objective-C运行时方法\u ExchangeImplements不起作用

Ios Objective-C运行时方法\u ExchangeImplements不起作用,ios,objective-c,runtime,Ios,Objective C,Runtime,下面是我的代码,请帮我找出这个错误的原因。 错误是 xxx\u objectAtIndex:NSUIntegerindex不工作 代码: 我认为你应该这样做 BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), m

下面是我的代码,请帮我找出这个错误的原因。 错误是

xxx\u objectAtIndex:NSUIntegerindex不工作

代码:

我认为你应该这样做

       BOOL didAddMethod =
            class_addMethod(class,
                originalSelector,
                method_getImplementation(swizzledMethod),
                method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                swizzledSelector,
                method_getImplementation(originalMethod),
                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }

当我使用您的方法时,始终不能以这种方式执行xxx\u objectAtIndex:in class\u getInstanceMethod方法您使用的类。尝试使用self。我在UIViewController中使用这种方式,交换视图将显示并成功,但在NSArray失败时使用这种方式您在哪个类中执行此操作?UIViewController和NSArray
       BOOL didAddMethod =
            class_addMethod(class,
                originalSelector,
                method_getImplementation(swizzledMethod),
                method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                swizzledSelector,
                method_getImplementation(originalMethod),
                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }