gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:01:37 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com