如果你正在实现一个子类,你可以在你的实现中显式调用父类(super class)的方法,即使你已经覆盖了那个方法,即:
[self overriddenMethod]; //calls the subclass's method
[super overriddenMethod]; //calls the superclass's method
如果你想从子类实现之外的某个地方调用父类(super class)的方法怎么办,即:
[[object super] overriddenMethod]; //crashes
这可能吗?并且通过扩展,是否有可能在实现中上升到不止一个级别,即:
[[super super] overriddenMethod]; //will this work?
最佳答案
一个更愉快的选择(用于调试)是添加一个类别方法来为您完成:
- (void) callSuperMethod { [super overriddenMethod]; }
事实上,没有更方便的方法来做到这一点,这在很大程度上是设计使然。
关于iphone - 如何从其他地方调用 Objective-C 对象父类(super class)的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2877251/