【发布时间】:2014-10-02 13:59:24
【问题描述】:
所以我有一个类层次结构如下:
@interface MyClass : ParentClass
-(void)myMethod
{
[super myMethod];
// some specific operation
}
@end
@interface ParentClass : ParentParentClass
-(void)myMethod
{
[super myMethod];
// some specific operation
}
@end
@interface ParentParentClass : ParentParentParentClass
-(void)myMethod
{
[super myMethod];
// some specific operation
}
@end
现在假设,在MyClass 中,我想避免调用ParentClass 的myMethod,而是想在ParentParentClass 中调用myMethod。
我该怎么做?
我已经尝试投射 super 但这不起作用。
【问题讨论】:
-
[super [super myMethod]];应该可以工作。你遇到了什么错误? -
@Droppy 我想你的意思是
[[super super] myMethod] -
@PartiallyFinite 我愿意。
-
你为什么想要这样的东西?
-
@Popeye 这听起来像是一些非常糟糕的设计,这可能是它不可能的原因。
标签: objective-c