I know that many methods need to call its super class method and some methods dont need,
I'm looking about sth about method swizzling.It's initialized in the load method,and in the tutorial there is no [super load]
.
i'm wondering if it's wrong or there is just no need to call [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");
}
By the way,this method is used to fix the navigation corruption.
I happened to reappear the problem sometimes,and i debuggered it,i think it's about the thread.So i make this swizzling to add sth in the system method.
If you can tell sth about the navigation corruption problem or this method swizzling,i also very appreciate that.
From the NSObject
documentation
(emphasis added):
A class’s
+load
method is called after all of its superclasses’+load
methods.
Which means that you don't have to call [super load]
from your code.
The load
method from all superclasses has already been called
by the Objective-C runtime before the method in your subclass is called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With