从超类到达子类的成员

时间:2011-09-16 08:16:36

标签: objective-c ios oop

[抱歉我的英语不好]

我有超类,它的子类(子类) - 子类是一些视图 sprite - 超类有一些辅助函数,例如用于触发动画的函数。

我想在子类中调用'fire the animation',但它在超类中显示。 我需要访问子类视图(将动画的viewsprite添加到子类中的self.view)

如何从超类到达子类成员? : - /

1 个答案:

答案 0 :(得分:1)

@interface MONBase : NSObject
// example action. required override
- (void)performSomeAction;
// example accessor. required override
- (MONThing *)thing;
@end

@implementation MONBase

- (void)performSomeAction
{
    assert(0 && "required override");
}

- (MONThing *)thing
{
    assert(0 && "required override");
    return nil;
}

- (void)example
{
    MONThing * thing = [self thing];
    [self configureThing:thing];
    [self performSomeAction];
}

@end

@interface MONSubclass : MONBase
@end

@implementation MONSubclass

- (void)performSomeAction
{
    [self doStuff];
}

- (MONThing *)thing
{
    return self.something;
}

@end