From: Arno P. <ar...@pu...> - 2009-10-28 21:48:13
|
there is one problems with Objective-C categories: you can overwrite an existing method (such as drawRect) but there is no way to access the original implementation (the one that you 'covered up'). When using inheritance, it is sometimes necessary to access the implementation of the base class (that is what the keyword 'super' is for). If you use a category for drawRect, you would not be able to access the original implementation in UIView. Apart from the fact the drawRect is doing quite a few things (e.g., iterate over all sub-views). You would need to replicate that behavior in your own implementation of drawRect. Note that a category replaces the implementation of drawRect for *all* widgets (UILabel, etc, etc). You can only use a category for 'cover up' a method that someone might override only if (1) you are sure nothing happens in the implementation of that method in the base class (i.e., the method is abstract) and (2) you don't need to access the implementation via super. Arno Panayotis Katsaloulis wrote: > I try to understand one thing - it doesn't really make sense to me. > > In UIView inheritance is used to call > drawRect:(CGRect)rect > because it doesn't work otherwise. I tried it too without inheritance > and failed. > > But, in the similar issue with viewDidLoad from UIViewController, > which I simply did something like: > > - (void) viewDidLoad { > [self viewDidLoad__]; > } > - (void) viewDidLoad__ { > } > > there wasn't a need to use inheritance. viewDidLoad__ was called in > any case. > Any ideas why in the first case, inheritance was required, but in the > second it was not? > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |