をsuper viewController呼び出し、を呼び出しrootViewControllerてsubClass、を初期化し、を削除します。UIViewControllerinitNotificationdeallocNotification
そして、あなたのすべての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: