Ios Objective-C运行时方法\u ExchangeImplements不起作用
下面是我的代码,请帮我找出这个错误的原因。 错误是 xxx\u objectAtIndex:NSUIntegerindex不工作 代码: 我认为你应该这样做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
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);
}