Can category methods be overridden? IOS

假装没事ソ 提交于 2020-02-13 07:14:26

问题


I am trying to plan how to add a couple methods to all instances of certain objects. I think adding a category to the parent object(UIViewController) would work for what I want to do, but can I override a method added this way? Most of the time the subclasses will use the default methods but I do know I will need to override the method at least once.

Also what other methods should I consider for what I am trying to do?

Example of what I am trying to do:

I have a set of Objects that act like pages of a journal. These pages are subclasses of UIViewControllers. I want to add methods for loading, saving, and similar. In a journal class(Subclass of NSObject) I have an array storing instances of each Journal page. I want it so I can select a page from the array and run on of the methods without having to know the specific object class as they all should have the methods.


回答1:


Short answer: yes, you can. For purposes of inheritance category methods on a superclass are treated like methods that are actually defined in the superclass, and can be overridden in the same way.



来源:https://stackoverflow.com/questions/11509813/can-category-methods-be-overridden-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!