2010-07-14 36 views
0

嘿,那麼我有一個NSObject子類通過通知中心發送消息,並且我將通知發送給對象nil,但唯一的對象是收到通知是一個向他們發送NS通知只在同一個對象內發送

我有兩個通知在同一時間被髮送出去(以測試它是否是一個線程問題)

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

int status = 123; 
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"RAR" forKey:@"Status"]; 
NSNotification *note = [NSNotification notificationWithName:kWGAskingForAuthToken object:nil userInfo:userInfo]; 
[[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:note waitUntilDone:YES]; 

,我的觀察是一樣簡單

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMyEvent:)name:kWGAskingForAuthToken object:nil]; 

這是在不接收通知的單獨對象中的相同觀察者

回答

0

這看起來像正確的方式給我。唯一的問題是「kWGAskingForAuthToken在哪裏定義?」它是否可能在多個地方定義?可能有所不同?

+0

恐怕是正確定義(因爲它們都已經包括一個NSString常數) 是什麼使得它有點令人沮喪的是,我有一個日誌通過回聲出數百個,但從來沒有我自己 中心全力以赴通知 ([[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(log :) name:nil object:nil];) – orta 2010-07-15 10:32:55

0

這是一個恥辱,但我從來沒有設法找到答案,而是我開始發送消息給對象而不是全局使用它們。