このメソッドに- (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 でクラッシュします。どうしたの?