调用并在super viewController
中初始化并在中删除rootViewController
subClass
UIViewController
init
Notification
dealloc
Notification
然后所有你viewController
应该subClass
的rootViewController
。这只是OOP
像 :
@interface RootViewController : UIViewController
@end
@implementation RootViewController
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (id)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
}
return self;
}
- (void)reachabilityChanged:(NSNotification *)notification
{
// you can do nothing , it should be override.
}
And when you creat your viewController , you should subclass the RootViewController
@interface YourViewController : RootViewController
- (void)reachabilityChanged:(NSNotification *)notification
{
// if your super class method do some things you should call [super reachabilityChanged:notification]
// do your thing.
}
@end
In the implementation
you should achieve the reachabilityChanged:
method