2010-07-14 54 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

这是一个耻辱,但我从来没有设法找到答案,而是我开始发送消息给对象而不是全局使用它们。