我知道很多方法需要调用它的超类方法,有些方法不需要,
我正在寻找关于方法混合的方法.它在load方法中初始化,在教程中没有[super load]
.
我想知道它是错还是没有必要打电话[super load]
.
+ (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class class = [self class]; // When swizzling a class method, use the following: // Class class = object_getClass((id)self); SEL originalSelector = @selector(pushViewController:animated:); SEL swizzledSelector = @selector(flbs_pushViewController:animated:); Method originalMethod = class_getInstanceMethod(class, originalSelector); Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (didAddMethod) { class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); } else { method_exchangeImplementations(originalMethod, swizzledMethod); } }); } #pragma mark - Method Swizzling - (void)flbs_pushViewController:(UIViewController *)viewController animated:(BOOL)animated { dispatch_async(dispatch_get_main_queue(), ^{ [self flbs_pushViewController:viewController animated:animated]; }); NSLog(@"flbs_pushViewController"); }
顺便说一句,此方法用于修复导航损坏.
我碰巧有时会重新出现这个问题,我调试了它,我认为这是关于线程的.所以我在制度方法中添加某些东西.
如果你能告诉某人导航损坏问题或这种方法调整,我也非常感激.
从NSObject
文档
(重点添加):
一个类的
+load
方法被调用后,它的所有超+load
的方法.
这意味着您无需[super load]
从代码中调用.在load
所有超类的方法已经被调用由Objective-C运行时之前,在子类中的方法被调用.