ios - 发布 nsnotification 但观察者没有听到

标签 ios objective-c nsnotificationcenter

我正在使用 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/

相关文章:

iphone - stringWithContentsOfURL 和 HTTP 500 错误代码

iphone - viewWillDisappear 和 viewDidDisappear 永远不会被调用

ios - 主页按钮和 ApplicationState。重新启动应用程序时调用哪个委托(delegate)方法?

ios - 以编程方式退出 AVPlayerViewController 全屏?

ios - 在保持背景动态的同时向 View 添加动画模糊

objective-c - IOS:默认属性值

ios - 类型 'ViewController' 不符合协议(protocol) 'Wsdl2CodeProxyDelegate'

ios - 重写drawRect : in UITableViewCell

ios - 需要帮助解除模态呈现的 ViewController 并从 UINavigationController 弹出 ViewController

iOS、Swift、Objective C、UserNotificationCenter、NSNotificationCenter