Override a method but leave superclass's calls to that method going to superclass's version of that method

StackOverflow https://stackoverflow.com/questions/14513741

Question

Is it possible to override a method in a subclass in such a way that when the superclass calls the method, those calls still go to the original method, but all other (external) calls to the method go to the overridden version?

Background: If I subclass a UITextField and override the getter for delegate, the built-in behavior of UITextField that relies on the delegate appears to be using the backing ivar to access the delegate (and not touching the overridden getter); however, if I try the same thing with UITextView, it seems that the internal behavior of UITextView that relies on the delegate uses the overridden getter to access the delegate.

No correct solution

OTHER TIPS

you can use the objc runtime functions

#import <objc/message.h>

objc_super superstruct = {self, [UITextField class]};
objc_msgSendSuper(&superstruct, _cmd, args...);

I believe you did something wrong the second time.
You are saying that subclassing UITextView and overriding a method....affects the superclass??
Doesn't sound right at all.
I'd suggest making sure the view you used is an object of the overriden class and not of the default UITextView class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top