2017-05-08 17 views
0
+ (void)load { 
    [super load]; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     Class aClass = [self class]; 
     SEL selector = @selector(setBackgroundColor:); 
     SEL _selector = @selector(cusSetBackgroundColor:); 

     Method method = class_getInstanceMethod(aClass, selector); 
     Method _method = class_getInstanceMethod(aClass, _selector); 

     BOOL did = class_addMethod(aClass, selector, method_getImplementation(_method), method_getTypeEncoding(_method)); 
     if (did) { 
      class_replaceMethod(aClass, _selector, method_getImplementation(method), method_getTypeEncoding(method)); 
     } else { 
      class_addMethod(aClass, _selector, method_getImplementation(_method), method_getTypeEncoding(_method)); 
      method_exchangeImplementations(method, _method); 
     } 
    }); 
} 
- (void)cusSetBackgroundColor:(UIColor *)backgroundColor 
{ 
    NSLog(@"test swizzling"); 
    [self cusSetBackgroundColor:backgroundColor]; 
} 

「UITableView + Swizzling」に入れたとき。 iPad Proを選択します。それはクラッシュするでしょう。Xcode8 + ipad。メソッドSwizzling UITableView backgroundColorクラッシュ

クラッシュログは次のとおりです。アサーションエラーvoid PushNextClassForSettingIMP(id、SEL())。アプリを終了 キャッチされない例外により 'にNSInternalInconsistencyException' が

.....なぜiPad用

答えて

0

をkonwません。 私は 'p class_getInstanceMethod(aClass、@セレクタ(setBackgroundColor :))'を実行します コンソールは関数アドレスを出力できません。 がiPhone用です。私は住所を得ることができます。

ので、私は.. 'のp class_getInstanceMethod(AClassは、@selector(_setBackgroundColorを))'

を解決

問題を試みたが、それだけでとても奇妙です。もしあなたが他のソルーションを知っていたら。 私に教えてください。

0

私と同じクラッシュがあり、解決したのはUITableViewの代わりにUIViewを使用したことです。