我正在使用 NSNotifiationCenter,就像其他 1000 次一样,并发布通知,但我的观察者没有听到它?给了什么?
=== 这是我的表格 View ===
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleSuccessSocket)
name:kNotificationServiceStartSuccessful
object:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleFailedSocketConnection)
name:kNotificationSocketFailedToConnect
object:self];
}
=== 这在我的 SOCKETMANAGER 中(如果重要的话,socket 管理器是一个单例)===
-(void)willStartService {
....
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationServiceStartSuccessful object:nil];
....
}
我已经调试并且在我的 View 中调用了 viewDidLoad。是的,正在调用我的 willStartService。
最佳答案
您只为自己发送的通知注册 TableView。应该是..
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleSuccessSocket)
name:kNotificationServiceStartSuccessful
object:nil];
关于ios - 发布 nsnotification 但观察者没有听到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24414179/