我需要覆盖在此方法中- (void)viewWillAppear:(BOOL)animated
添加的所有 ViewController 。NSLog(@"blabla")
即在每次调用 viewWillAppear 调用后实现 viewWillAppear + 我的 NSLog 消息的早期实现。可能吗?如果是的话,请给我一个建议。
目前我已经尝试过这段代码
@implementation RuntimeTest
IMP previusImp;
IMP newIMP;
- (void)ovverrideViewWillAppearInViewController:(Class)vcClass {
newIMP = class_getMethodImplementation([self class], @selector(viewWillAppear:));
Method viewWillAppearMethod = class_getInstanceMethod(vcClass, @selector(viewWillAppear:));
previusImp = method_setImplementation(viewWillAppearMethod, newIMP);
}
- (void)viewWillAppear:(BOOL)animated {
previusImp(self, @selector(viewWillAppear:), animated);
NSLog(@"log2");
}
@end
然后我有
@implementation IRViewController2
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"log");
}
@end
我的自定义viewWillAppear
首先调用,然后viewWillAppear
从IRViewController2
. 在此之后,我的应用程序因 EXC_BAD_ACCESS 而崩溃。怎么了?