There is no load method to override in UITableView. I suppose it is the constructor. But then class_getInstanceMethod and method_exchangeImplementations are unavailable.
#import <objc/runtime.h>
#import <objc/message.h>
@implementation UITableView (FixUITableViewAutolayoutIHope)
+ (void)load
{
Method existing = class_getInstanceMethod(self, @selector(layoutSubviews));
Method new = class_getInstanceMethod(self, @selector(_autolayout_replacementLayoutSubviews));
method_exchangeImplementations(existing, new);
}
- (void)_autolayout_replacementLayoutSubviews
{
[super layoutSubviews];
[self _autolayout_replacementLayoutSubviews]; // not recursive due to method swizzling
[super layoutSubviews];
}
@end