单个通知到多个对象? [英] Single Notification to multiple objects?

查看:121
本文介绍了单个通知到多个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有方法发布单一通知,并有两个不同的对象执行两种不同的方法?

Is there a way to post single notification and have two different objects execute two different methods?

[[NSNotificationCenter defaultCenter] postNotificationName:@"locationAdded" object:nil];

OBJECT ONE

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

OBJECT TWO

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



. . .

或者我怀疑我需要发布两个独立的通知, / p>

Or as I suspect would I need to post two separate notifications with unique names (i.e.)

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateTable" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateMapView" object:nil];


推荐答案

通知会传递给每个观察者,在发布之前添加。
所以你只需要一个通知。选择器可以不同。

The notification gets delivered to each observer, which has been added before posting it. So you need only a single notification. The selectors can be different.

这篇关于单个通知到多个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆