我知道很多方法需要调用它的超类方法,有些方法不需要,
我正在寻找关于方法调配的东西。它在加载方法中初始化,在教程中没有[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");
}
顺便说一句,此方法用于修复导航损坏。
我碰巧有时会再次出现问题,我对其进行了调试,我认为这是关于线程的。所以我做了这个混搭以在系统方法中添加一些东西。
如果您能说出导航损坏问题或这种方法的混乱,我也非常感谢。