1

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
  1. これは 100%UICollectionViewCellカテゴリです。
  2. この時点で、クラス+(void) loadのみUITableViewCellが渡されます (予想どおり)
4

1 に答える 1

1

問題が見つかりました。メソッドをオーバーライドしないサブクラスのメソッドをスウィズルすると、そのスーパー クラス メソッドがオーバーライドされます。そのスーパークラスは一部のセレクターに応答できませんでした。もちろん、これは事実です。

ところで助けてくれてありがとう

于 2015-02-21T22:20:51.570 に答える