Search code examples
iosobjective-cuitextviewdelegate

Can Subclass use a delegate method of superclass Ios


Is it possible to use a delegate of superclass on subclass

Example: Class A is superclass of class B and superclass A uses the text view method example textviewDidChange. can I somehow call [super textViewDidChange] of superclass A on Subclass B even it isn't on header file of class A if i rediclare the method on subclass B


Solution

  • When you specify UITextViewDelegate, you're telling the compiler that your class meets the specifications for a UITextViewDelegate. If class A has all the requirements for a UITextViewDelegate, and class B is a subclass, then it too will have all the requirements. Nothing will stop you from assigning any instance as a delegate, so you still have to be careful with that.