ManuQiao ManuQiao - 1 year ago 83
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*/

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download