NSNotificationCenter
第一种,这个只是传值,通过NSNotification获取,当然也可以直接使用obj
注册A
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableOrDisableAudio:) name:@"enableOrDisableAudio" object:nil];
- (void)enableOrDisableAudio:(NSNotification *)notification
{
printf("enableOrDisableAudio\n");
BOOL bIsEnableAudio = [[notification object] boolValue];
self.m_bIsEnable = bIsEnableAudio;
[self enableAudio:bIsEnableAudio];
}
响应B
NSNumber *boolNum = [NSNumber numberWithBool:m_bIsSPKOn];
[[NSNotificationCenter defaultCenter] postNotificationName:@"enableOrDisableAudio" object:boolNum];
第二种多值传输(obj)
注册A
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object: nil];
- (void)reachabilityChanged:(NSNotification *)note
{
Reachability *curRech = [note object];
NetworkStatus status = [curRech currentReachabilityStatus];
if (status == NotReachable)
{
[self setStatusBarToShow];
[SVStatusHUD showWithMessage:Localized(@"disconnect from network") duration:KShortDuration];
}
else
{
[self resetStatusBarBlank];
}
}
响应B
Reachability* noteObject = (Reachability*) info;
// Post a notification to notify the client that the network reachability changed.
[[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject];
数组传输,注意响应消息的userInfo一定是NSDictionary类型
- (void) keyboardWillShow:(NSNotification *)aNotification
{
NSDictionary *userInfo = [aNotification userInfo];
}
分享到:
相关推荐
SwiftNotes - 围绕NotificationCenter的一个超级简单封装
主要给大家介绍了关于Swift中通知中心(NotificationCenter)使用的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
一个关于NotificationCenter的例子
MagicSwift巴士使用具有EventBus风格的NotificationCenter什么是MagicSwiftBus? 轻松实现对象之间的发布-订阅通信。 不要因缺少字符而浪费时间进行崩溃,而应使用enum。 不要将NSNotification用作方法的参数,请...
COCOS2D-X之NotificationCenter的用法
通知中心该存储库随附以下博客文章:
使用java InvocationHandler 静态类型接口,防止输入错误,如果更改方法名称或参数类型,则观察者将不进行修改而无法编译 不使用反射 ## maven依赖 <groupId>com.yy</groupId> <artifactId>notification-...
基于Continueum NotificationCenter的轻量级UI / AnyObject活页夹。 最后一个类ViewController:UIViewController {@IBOutlet弱var标签:UILabel! 私有let viewModel:ViewModel = ViewModel()私有基于Continuum ...
NotificationCenter nc = NotificationCenter . defaultCenter(); nc . addListener( new NotificationListener< SomeNotification> ( SomeNotification . class) { @Override public void onNotification ( ...
通知中心 ... 该库的工作方式类似于Objective-C和Swift NSNotificationCenter也类似于Android平台中的BroadcastReceiver 。...要在NotificationCenter中使用Key添加操作,您应使用以下代码: Notificatio
资源分类:Python库 所属语言:Python 资源全名:pyobjc-framework-NotificationCenter-5.1.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
iOS开发基础-NSNotificationCenter(通知中心)通知发布者和监听者示例,代码DEMO附带详细注释。有错误的地方欢迎提出。
4_NotificationCenter
NoticeObserveKit NoticeObserveKit是类型安全的NotificationCenter包装器。 // .keyboardWillShow是静态属性。 Notice.Center.default.observe(name:.keyboardWillShow){在此情况下,keyboardI NoticeObserveKit...
使用Swift 3,使用NotificationCenter更简洁,因此我们建议直接使用NotificationCenter.default 。 Kugel使用NotificationCenter的唯一功能是使用notification name => selector映射一次性订阅多个事件,但这可以...
迅捷笔记 周围的超级简单包装器。 设置 pod 'SwiftNotes' 或者只是将放到您的项目中。 UIKit通知示例 UIKeyboard通知 when (....when (.... static let somethingHappened = Notification....// send your cust
iOS通知中心操作iOSiOSiOSiOSiOS NotificationCenter NotificationCenter
公告中心适用于ownCloud的公告中心应用(允许管理员为用户发布公告) 取决于后端主分支上的质量检查指标:屏幕截图公告首页(“添加公告”表单仅适用于管理员)还通过流中的活动通知用户(无法禁用)
EV通知中心 例子 要运行示例项目,请克隆存储库,然后首先从Example目录运行pod install 。 要求 安装 EVNotificationCenter可通过。 要安装它,只需将以下行添加到您的Podfile中: pod 'EVNotificationCenter' ...
通知中心 网络通知中心的 PoC