如何覆盖继承类的方法
问题描述:
所以我使用core-plot,我必须覆盖CPTLayer中用于CPTAxisLabel的方法,但不是所有标签,所以我制作了一个CustomCPTAxisLabel类来执行此操作。 问题是我必须重写renderAsVectorInContext巫婆是从CPTLayer的方法, CPTAxisLabel继承CPTLayer和CustomCPTAxisLabel继承CPTAxisLabel(如下所示:CPTLayer-> CPTAxisLabel-> CustomCPTAxisLabel)。问题是我如何重写CustomCPTAxisLabel中的CPTLayer方法?如何覆盖继承类的方法
答
在子类CustomCPTAxisLabel,定义方法,它要覆盖renderAsVectorInContext。喜欢的东西
- (空)renderAsVectorInContext:(CGContextRef)上下文{
[super renderAsVectorInContext:context]; // Do customisation after this.
}
您可能会或可能不会选择在重写此方法CPTAxisLabel类,但如果你确实打电话给超级班。
我都准备好了,但是这个方法并没有被调用,我也不知道为什么...... – edo 2014-09-10 09:09:33
你可以从_CustomCPTAxisLabel_类发布一些代码。此外,您为其分配对象的代码。 – Gandalf 2014-09-10 09:35:10
在.H我已#IMPORT “CPTAxisLabel.h” 接口CustomCPTAxisLabel:CPTAxisLabel - (无效)renderAsVectorInContext:(CGContextRef)上下文; end and in .m @implementation CustomCPTAxisLabel - (void)renderAsVectorInContext:(CGContextRef)context {0;}} {super renderAsVectorInContext:context]; } – edo 2014-09-10 09:58:05