創(chuàng)建NSNotificationCenter的子類
@interface MyNotificationCenter : NSNotificationCenter
@end
@implementation MyNotificationCenter
+ (void)load {
Method origin = class_getInstanceMethod([self class],@selector(removeObserver:));
Method current = class_getInstanceMethod([self class],@selector(_removeObserver:));
method_exchangeImplementations(origin, current);
}
- (void)_removeObserver:(id)observer {
NSLog(@"調用移除通知方法: %@",observer);
//[self _removeObserver:observer];
}
@end
當VC被釋放時跪解,即使我們不在dealloc中寫
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
我們的Log依然會觸發(fā)只恨,且可以在log中找到vc對象