小编cl.*_*cl.的帖子

发布两个 NSNotification 时的执行顺序

一个关于NSNotification......的快速问题如果我NSNotifications在一个方法中发布两个,并且它们被不同的对象观察到,选择器方法的执行顺序是什么?

例如,如果我有三个控制器 - 海报、接收器 A 和接收器 B。在海报控制器的功能中,我执行以下操作:

[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceiverADoSomething" object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceiverBDoSomething" object:self];
Run Code Online (Sandbox Code Playgroud)

在接收者 A 的 viewDidLoad 方法中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(workToDoByA:) name:@"ReceiverADoSomething" object:nil];
Run Code Online (Sandbox Code Playgroud)

在接收者 B 的 viewDidLoad 方法中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(workToDoByB:) name:@"ReceiverADoSomething" object:nil];
Run Code Online (Sandbox Code Playgroud)

会先做workToDoByA再做workToDoByB吗?还是会一起被处决?

另一种情况......如果我有海报 A 发布通知,但有两个观察者到同一通知。那么执行顺序是什么?

在此先感谢您的帮助。

xcode objective-c nsnotifications nsnotificationcenter ios

3
推荐指数
1
解决办法
662
查看次数