I've been looking at some third-party code that adds a class category to UITableView; the interface adds three methods, but the implementation also includes code for the -dealloc method (among other helper methods).
I'm not super familiar with class categories - aside from this seeming like a bad thing to do, does this override the -dealloc method for all instances of UITableView - even if the category is not imported by a particular class (say a ViewController) that instantiates a UITableView?
Toss that code as it is clearly garbage (post a link to it, if you can).
Assuming it really is a category on UITableView
, that dealloc
will effectively replace -- override, but without inheritance -- the class's normal dealloc
, thereby guaranteeing misbehavior. Not only will it destroy the functionality of all instances of UITableView, it'll mess up all subclasses, too.
Even if it isn't a category on UITableView
, but some attempt to organize code, then the dealloc
is in the wrong place. It should always be on the class's primary @implementation
. Just like a class cluster will implement all primitive methods on the main implementation -- dealloc
is very much a primitive method (where a "primitive" method is a method that is core to a class's functionality and is only implemented in terms of other primitive methods).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.