1

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

Aragunz
  • 511
  • 5
  • 18

2 Answers2

4

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.

Mike Dimmick
  • 9,662
  • 2
  • 23
  • 48
Owen Hartnett
  • 5,925
  • 2
  • 19
  • 35
  • Also make sure you specify the class that is implementing the delegate methods like you would for the superclass – G_Money Apr 24 '14 at 13:37
  • im not sure if i understand the part assigning any instance s delegate and G_Money;s sentence specify the class implementing the delegate sorry english not my first im sure u explained it well but my languange knowlege needs to be more specific so u both are saying if i have textfieldDidChange again in subclass it automatically gets all from A and extra things u put on B ? – Aragunz Apr 24 '14 at 13:44
  • In other words, there's no checking that the instance you said was a delegate has actually implemented all the required methods. When you assign the delegate as `myTextView.delegate = theSubclass` the compiler assumes you know what you're doing and that `theSubclass` actually meets the delegate specs. – Owen Hartnett Apr 24 '14 at 13:58
2

Yes,you can. Since class A confirms <UITextViewDelegate> protocol there is no need to redeclare them in header file. Just make sure it implements needed methods.

user2260054
  • 522
  • 1
  • 3
  • 11