发布两个 NSNotification 时的执行顺序
关于 NSNotification 的一个简单问题...如果我在一个方法中发布两个 NSNotification,并且它们被不同的对象观察,那么选择器方法的执行顺序是什么?
例如,如果我有三个控制器 - Poster、Receiver A 和 Receiver B。在 Poster 控制器的函数中,我执行以下操作:
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceiverADoSomething" object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceiverBDoSomething" object:self];
在接收器 A 的 viewDidLoad 方法中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(workToDoByA:) name:@"ReceiverADoSomething" object:nil];
在接收器 B 的 viewDidLoad 方法中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(workToDoByB:) name:@"ReceiverADoSomething" object:nil];
Will 先完成workToDoByA
,然后再完成workToDoByB
? 还是一起被处决?
另一种情况...如果我让海报 A 发布通知,但同一个通知有两个观察者。那么执行顺序是怎样的呢?
预先感谢您的帮助。
A quick question about NSNotification
... If I post two NSNotifications
in a method, and they are observed by different objects, what is the sequence of execution of the selector method?
For instance, if I have three controllers - Poster, Receiver A and Receiver B. In a function of the Poster controller, I do the following:
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceiverADoSomething" object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceiverBDoSomething" object:self];
In the viewDidLoad method for receiver A:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(workToDoByA:) name:@"ReceiverADoSomething" object:nil];
In the viewDidLoad method for receiver B:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(workToDoByB:) name:@"ReceiverADoSomething" object:nil];
Will workToDoByA
be done first followed by workToDoByB
?
Or they will be executed together?
Another scenario... If I have Poster A posting a notification but there are two observers to the SAME notification. What is the execution sequence then?
Thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
摘自 Apple 文档:
postNotificationName 的策略相同。
A excerpt from Apple docs:
the same policy is for postNotificationName.