我在UITableViewCell
类别上调配方法时出现意外行为
我的.m
文件:
#import "UICollectionViewCell+CostraintFix.h"
#import <objc/runtime.h>
@implementation UICollectionViewCell (CostraintFix)
+(void)load {
Method original_setBounds, swizzled_setBounds;
original_setBounds = class_getInstanceMethod(self, @selector(setBounds:));
swizzled_setBounds = class_getInstanceMethod(self, @selector(swizzled_setBounds:));
method_exchangeImplementations(original_setBounds, swizzled_setBounds);
}
- (void) swizzled_setBounds:(CGRect) bounds{
[self swizzled_setBounds:bounds];
self.contentView.frame = bounds;
}
@end
好吧,当我开始我的项目时,我有这个:
-[UINavigationButton swizzled_setBounds:]: unrecognized selector sent to instance 0x7fe2dbb301c0
- 这是 100% 的一个
UICollectionViewCell
类别。 - 此时,在 中
+(void) load
,只有UITableViewCell
类通过(如预期的那样)