Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 调用超级方法时跳过超级类?_Ios_Objective C - Fatal编程技术网

Ios 调用超级方法时跳过超级类?

Ios 调用超级方法时跳过超级类?,ios,objective-c,Ios,Objective C,这似乎有些奇怪,但我想做以下几点: 甲级 - (void)someMethod; B类:A - (void)someMethod; // overrides 丙类:乙类 - (void)someMethod; // overrides 在类C中,我想重写两个超类中存在的方法,但在[super methodName]调用中只调用类a的方法 - (void)someMethod { [super someMethod]; // but I want to call class A, no

这似乎有些奇怪,但我想做以下几点:

甲级

- (void)someMethod;
B类:A

- (void)someMethod; // overrides
丙类:乙类

- (void)someMethod; // overrides
在类C中,我想重写两个超类中存在的方法,但在[super methodName]调用中只调用类a的方法

- (void)someMethod
{
  [super someMethod];  // but I want to call class A, not B
}

可能吗?

好吧,你可以做一个黑客解决方案,你把一个整数参数传递到方法中,这个参数在每次超级调用时递减,这样每个方法实现只调用它的超类方法,直到最后你达到0,然后你实际执行这个方法。这有点像一种奇怪的递归形式。

类似的东西应该可以工作:

// in Class C:
#import <objc/runtime.h>

- (void)someMethod
{
    // I want to call class A's implementation of this method

    IMP method = class_getMethodImplementation([ClassA class], _cmd);

    method(self, _cmd);

}
//在C类中:
#进口
-(无效)某种方法
{
//我想调用这个方法的类A的实现
IMP method=class_getMethodImplementation([ClassA class],_cmd);
方法(self,_-cmd);
}

是的,我曾考虑过类似的解决方案,但我希望有一个更封装的解决方案。我不知道这是否可能@Javy——如果你这么做了,肯定会对它进行很好的注释。这种方法是否适用于返回某些内容的方法?我想从super super返回一个CGSize。我们能一起传递一个参数吗?如果可能,请添加返回类型和参数。