简体   繁体   English

子类可以使用超类Ios的委托方法吗

[英]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. 示例:类A是类B的超类,而类A使用文本视图方法示例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 如果我重新声明子类B的方法,我可以以某种方式在子类B上调用超类A的[super textViewDidChange]吗,即使它不在类A的头文件中

When you specify UITextViewDelegate , you're telling the compiler that your class meets the specifications for a UITextViewDelegate . 当指定UITextViewDelegate ,就是在告诉编译器您的class符合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. 如果class A具有UITextViewDelegate所有要求,而class B是子类,则它也将具有所有要求。 Nothing will stop you from assigning any instance as a delegate , so you still have to be careful with that. 没有什么会阻止您将任何instance分配为delegate ,因此您仍然必须小心。

Yes,you can. 是的你可以。 Since class A confirms <UITextViewDelegate> protocol there is no need to redeclare them in header file. 由于类A确认<UITextViewDelegate>协议,因此无需在头文件中重新声明它们。 Just make sure it implements needed methods. 只要确保它实现了所需的方法即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM