を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.
}
そして、 viewController を作成するときは、サブクラス化する必要があります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
メソッドimplementation
を達成する必要がありますreachabilityChanged: