相关疑难解决方法(0)

如何阻止NSNotification中的Observer调用两次?

我有一个观察者NSNotification被叫两次.我不知道该怎么做.

我用谷歌搜索但没有找到解决方案.

[[NSNotificationCenter defaultCenter] addObserver:self
     selector:@selector(connectedToServer:) name:@"ConnectedToServer" object:nil];

- (void)connectedToServer:(NSNotification*)notification {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"SendMessageToServer" object:message];
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsnotifications ios

52
推荐指数
3
解决办法
3万
查看次数

为什么NSNotification中的Observer调用了两次....?

如果类是自定义类,则在发布通知后,对应于观察者的选择器将被调用两次.是否有更好的解决方案,以便只调用一次选择器?

cocoa notifications objective-c

5
推荐指数
2
解决办法
3854
查看次数