2015-10-01 53 views
0

我已經添加了一個來自AppDelegate的觀察者,並將此代碼放入didFinishLaunchingWithOptiong方法中。NSObject的NSNotificationCenter addObserver來自NSObject的子類

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; 
internetReachability = [Reachability reachabilityForInternetConnection]; 
[internetReachability startNotifier]; 

現在我想把這個addObserver我的自定義類是NSObject一個子類裏面?

編輯:

這是我reachabilityChanged方法:

- (void) reachabilityChanged:(NSNotification *)note 
{ 
    NSLog(@"change"); 
} 

我把這個方法在我稱之爲的addObserver

+0

問題是什麼? –

+0

reachabilityChanged方法沒有命中,如果我把它放在NSObject的子類上@Rage – indraep

+0

'reachabilityChanged:'選擇器在哪裏定義?在AppDelegate中? –

回答

0

爲了運行reachabilityChanged方法,你需要相同的類發佈您在AppDelegate註冊的通知如下

[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:nil];