ManuQiao ManuQiao - 3 months ago 34
Objective-C Question

Can I interrupt a method of a child in parent class?

I declared


ChildClass: ParentClass

Is it possible to interrupt the overridden method in ChildClass after 'do something in ParentClass' so that 'do something in ChildClass' will not be executed?


- (void)method
/*do something in ParentClass*/
/*try interrupting [child method]*/


- (void)method
[super method];
/*do something in ChildClass*/


No, you can't control a method up the call chain like this. Nor should a class have this sort of knowledge about its subclasses.

You'll have to find some way for ClassB to check the condition itself, whether via the return value from -[ClassA method], or by calling another method first, or checking it directly.